Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"phpstan/phpstan-strict-rules": "^0.12",
"webchemistry/testing-helpers": "^3.0.0"
},
"minimum-stability": "dev",
"minimum-stability": "stable",
"autoload": {
"psr-4": {
"Contributte\\FormWizard\\": [
Expand Down
25 changes: 25 additions & 0 deletions src/Facade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Contributte\FormWizard;

use Closure;
use LogicException;
use Nette\Application\UI\Form as UIForm;
use Nette\Forms\Form;
use Nette\SmartObject;
use Nette\Utils\ArrayHash;
Expand Down Expand Up @@ -108,6 +110,29 @@ public function isDisabled(int $step): bool
return !$this->wizard->getSteps()[$step];
}

public function attached(): void
{
if ($this->wizard instanceof Wizard) {
$this->wizard->callStartup();
}

$form = $this->wizard->create(null, false);

if ($form instanceof UIForm) {
throw new LogicException(sprintf('Cannot call this method on %s.', UIForm::class));
}

$submitted = (bool) $form->isSubmitted();
if ($submitted) {
$form->fireEvents();
}
}

public function renderCurrentComponent(): string
{
return (string) $this->getCurrentComponent();
}

/**
* @return mixed
*/
Expand Down
4 changes: 2 additions & 2 deletions src/IWizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Contributte\FormWizard;

use Nette\Application\UI\Form;
use Nette\Forms\Form;
use Nette\Utils\ArrayHash;

interface IWizard
Expand All @@ -26,7 +26,7 @@ public function render(): void;

public function reset(): void;

public function create(?string $step = null): Form;
public function create(?string $step = null, bool $defaultValues = true): Form;

public function isSuccess(): bool;

Expand Down
20 changes: 15 additions & 5 deletions src/Wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ protected function getSection(): WizardSessionSection

public function getStepCounter(): StepCounter
{
$counter = 1;
if ($this->stepCounter === null) {
for ($counter = 1; $counter < 1000; $counter++) {
$counter = 1;
for (; $counter < 1000; $counter++) {
if (!method_exists($this, 'createStep' . $counter) && !$this->getComponent('step' . $counter, false)) {
$counter--;
break;
Expand Down Expand Up @@ -278,7 +278,7 @@ public function reset(): void
$this->stepCounter = null;
}

public function create(?string $step = null): Form
public function create(?string $step = null, bool $defaultValues = true): Forms\Form
{
$step = (int) ($step ?? $this->getCurrentStep());
/** @var Form $form */
Expand All @@ -291,7 +291,9 @@ public function create(?string $step = null): Form
}

// Set submited values
$form->setValues((array) $this->getSection()->getStepValues($step));
if ($defaultValues) {
$form->setValues((array) $this->getSection()->getStepValues($step));
}

return $form;
}
Expand Down Expand Up @@ -380,7 +382,10 @@ public function getPresenter(): ?Presenter
return $this->presenter;
}

protected function validateParent(IContainer $parent): void
/**
* @internal only for standalone usage, use Facade instead of
*/
public function callStartup(): void
{
if (!$this->startupCalled) {
$this->startupCalled = true;
Expand All @@ -389,4 +394,9 @@ protected function validateParent(IContainer $parent): void
}
}

protected function validateParent(IContainer $parent): void
{
$this->callStartup();
}

}