Skip to content
Merged
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
84 changes: 0 additions & 84 deletions src/Form/Extension/Core/Type/FormFlowActionType.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Yceruto\FormFlowBundle\Form\Extension\Core\Type\FormFlowType;
use Yceruto\FormFlowBundle\Form\Flow\DataStorage\SessionDataStorage;
use Yceruto\FormFlowBundle\Form\Flow\FormFlowBuilderInterface;
use Yceruto\FormFlowBundle\Form\Flow\Type\FormFlowType;

class FormFlowTypeSessionDataStorageExtension extends AbstractTypeExtension
{
Expand Down
14 changes: 13 additions & 1 deletion src/Form/Flow/AbstractFlowType.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,22 @@
namespace Yceruto\FormFlowBundle\Form\Flow;

use Symfony\Component\Form\AbstractType;
use Yceruto\FormFlowBundle\Form\Extension\Core\Type\FormFlowType;
use Symfony\Component\Form\FormBuilderInterface;
use Yceruto\FormFlowBundle\Form\Flow\Type\FormFlowType;

abstract class AbstractFlowType extends AbstractType implements FormFlowTypeInterface
{
final public function buildForm(FormBuilderInterface $builder, array $options): void
{
\assert($builder instanceof FormFlowBuilderInterface);

$this->buildFormFlow($builder, $options);
}

public function buildFormFlow(FormFlowBuilderInterface $builder, array $options): void
{
}

public function getParent(): string
{
return FormFlowType::class;
Expand Down
16 changes: 0 additions & 16 deletions src/Form/Flow/ActionButtonBuilder.php

This file was deleted.

12 changes: 0 additions & 12 deletions src/Form/Flow/ActionButtonTypeInterface.php

This file was deleted.

35 changes: 13 additions & 22 deletions src/Form/Flow/ActionButton.php → src/Form/Flow/FlowButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

/**
* A button that submits the form and handles an action.

*/
class ActionButton extends SubmitButton implements ActionButtonInterface
class FlowButton extends SubmitButton implements FlowButtonInterface
{
private mixed $data = null;
private bool $handled = false;
Expand All @@ -33,21 +34,6 @@ public function getViewData(): mixed
return $this->data;
}

public function getAction(): string
{
return $this->getConfig()->getOption('action');
}

public function getHandler(): callable
{
return $this->getConfig()->getOption('handler');
}

public function isHandled(): bool
{
return $this->handled;
}

public function handle(): void
{
/** @var FormInterface $form */
Expand All @@ -58,30 +44,35 @@ public function handle(): void
$form = $form->getParent();
}

$handler = $this->getHandler();
$handler = $this->getConfig()->getOption('handler');
$handler($data, $this, $form);

$this->handled = true;
}

public function isHandled(): bool
{
return $this->handled;
}

public function isResetAction(): bool
{
return 'reset' === $this->getAction();
return 'reset' === $this->getConfig()->getAttribute('action');
}

public function isBackAction(): bool
public function isPreviousAction(): bool
{
return 'back' === $this->getAction();
return 'previous' === $this->getConfig()->getAttribute('action');
}

public function isNextAction(): bool
{
return 'next' === $this->getAction();
return 'next' === $this->getConfig()->getAttribute('action');
}

public function isFinishAction(): bool
{
return 'finish' === $this->getAction();
return 'finish' === $this->getConfig()->getAttribute('action');
}

public function isClearSubmission(): bool
Expand Down
16 changes: 16 additions & 0 deletions src/Form/Flow/FlowButtonBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Yceruto\FormFlowBundle\Form\Flow;

use Symfony\Component\Form\ButtonBuilder;

/**
* A builder for {@link FlowButton} instances.
*/
class FlowButtonBuilder extends ButtonBuilder
{
public function getForm(): FlowButton
{
return new FlowButton($this->getFormConfig());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,27 @@
use Symfony\Component\Form\ClickableInterface;
use Symfony\Component\Form\FormInterface;

interface ActionButtonInterface extends FormInterface, ClickableInterface
interface FlowButtonInterface extends FormInterface, ClickableInterface
{
/**
* Returns the action name configured for the button.
*/
public function getAction(): string;

/**
* Returns the callable handler configured for the button.
* Executes the callable handler.
*/
public function getHandler(): callable;
public function handle(): void;

/**
* Checks if the callable handler was already called.
*/
public function isHandled(): bool;

/**
* Executes the callable handler.
*/
public function handle(): void;

/**
* Checks if the button's action is 'reset'.
*/
public function isResetAction(): bool;

/**
* Checks if the button's action is 'back'.
* Checks if the button's action is 'previous'.
*/
public function isBackAction(): bool;
public function isPreviousAction(): bool;

/**
* Checks if the button's action is 'next'.
Expand Down
12 changes: 12 additions & 0 deletions src/Form/Flow/FlowButtonTypeInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Yceruto\FormFlowBundle\Form\Flow;

use Symfony\Component\Form\FormTypeInterface;

/**
* A type that should be converted into a {@link FlowButton} instance.
*/
interface FlowButtonTypeInterface extends FormTypeInterface
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Symfony\Component\Form\Exception\InvalidArgumentException;

class FormFlowCursor
class FlowCursor
{
/**
* @param array<string> $steps
Expand Down Expand Up @@ -38,7 +38,7 @@ public function getFirstStep(): string
return $this->steps[0];
}

public function getPrevStep(): ?string
public function getPreviousStep(): ?string
{
$currentPos = array_search($this->currentStep, $this->steps, true);

Expand Down Expand Up @@ -81,7 +81,7 @@ public function isLastStep(): bool

public function canMoveBack(): bool
{
return null !== $this->getPrevStep();
return null !== $this->getPreviousStep();
}

public function canMoveNext(): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Symfony\Component\Form\Exception\BadMethodCallException;
use Symfony\Component\Form\FormTypeInterface;

class FormFlowStepBuilder implements FormFlowStepBuilderInterface
class FlowStepBuilder implements FlowStepBuilderInterface
{
private bool $locked = false;
private int $priority = 0;
Expand All @@ -29,7 +29,7 @@ public function getName(): string
public function getType(): string
{
if ($this->locked) {
throw new BadMethodCallException('FormFlowStepBuilder methods cannot be accessed anymore once the builder is turned into a FormFlowStepConfigInterface instance.');
throw new BadMethodCallException('FlowStepBuilder methods cannot be accessed anymore once the builder is turned into a FlowStepConfigInterface instance.');
}

return $this->type;
Expand All @@ -38,7 +38,7 @@ public function getType(): string
public function getOptions(): array
{
if ($this->locked) {
throw new BadMethodCallException('FormFlowStepBuilder methods cannot be accessed anymore once the builder is turned into a FormFlowStepConfigInterface instance.');
throw new BadMethodCallException('FlowStepBuilder methods cannot be accessed anymore once the builder is turned into a FlowStepConfigInterface instance.');
}

return $this->options;
Expand All @@ -52,7 +52,7 @@ public function getPriority(): int
public function setPriority(int $priority): static
{
if ($this->locked) {
throw new BadMethodCallException('FormFlowStepBuilder methods cannot be accessed anymore once the builder is turned into a FormFlowStepConfigInterface instance.');
throw new BadMethodCallException('FlowStepBuilder methods cannot be accessed anymore once the builder is turned into a FlowStepConfigInterface instance.');
}

$this->priority = $priority;
Expand All @@ -77,18 +77,18 @@ public function isSkipped(mixed $data): bool
public function setSkip(?\Closure $skip): static
{
if ($this->locked) {
throw new BadMethodCallException('FormFlowStepBuilder methods cannot be accessed anymore once the builder is turned into a FormFlowStepConfigInterface instance.');
throw new BadMethodCallException('FlowStepBuilder methods cannot be accessed anymore once the builder is turned into a FlowStepConfigInterface instance.');
}

$this->skip = $skip;

return $this;
}

public function getStepConfig(): FormFlowStepConfigInterface
public function getStepConfig(): FlowStepConfigInterface
{
if ($this->locked) {
throw new BadMethodCallException('FormFlowStepBuilder methods cannot be accessed anymore once the builder is turned into a FormFlowStepConfigInterface instance.');
throw new BadMethodCallException('FlowStepBuilder methods cannot be accessed anymore once the builder is turned into a FlowStepConfigInterface instance.');
}

// This method should be idempotent, so clone the builder
Expand Down
Loading