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
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,35 @@
CHANGELOG
=========

0.4.0
-----
* [Breaking Changes] Renamed the Form Flow classes to follow Symfony's native naming convention (`<Thing>Flow` instead of `Flow<Thing>`). The `Yceruto\FormFlowBundle\Form\Flow` namespace is unchanged; only class names changed:

| Before | After |
|----------------------------|----------------------------------|
| `AbstractFlowButtonType` | `AbstractButtonFlowType` |
| `FlowButton` | `ButtonFlow` |
| `FlowButtonBuilder` | `ButtonFlowBuilder` |
| `FlowButtonInterface` | `ButtonFlowInterface` |
| `FlowButtonTypeInterface` | `ButtonFlowTypeInterface` |
| `FlowCursor` | `FormFlowCursor` |
| `FlowStepNode` | `StepFlowNode` |
| `FlowStepBuilder` | `StepFlowBuilder` |
| `FlowStepBuilderInterface` | `StepFlowBuilderConfigInterface` |
| `FlowStepConfigInterface` | `StepFlowConfigInterface` |
| `Type\FlowButtonType` | `Type\ButtonFlowType` |
| `Type\FlowFinishType` | `Type\FinishFlowType` |
| `Type\FlowNavigatorType` | `Type\NavigatorFlowType` |
| `Type\FlowNextType` | `Type\NextFlowType` |
| `Type\FlowPreviousType` | `Type\PreviousFlowType` |
| `Type\FlowResetType` | `Type\ResetFlowType` |

* [Breaking Changes] As a consequence of the type renames, the form type block prefixes changed: `flow_button` → `button_flow`, `flow_finish` → `finish_flow`, `flow_navigator` → `navigator_flow`, `flow_next` → `next_flow`, `flow_previous` → `previous_flow`, `flow_reset` → `reset_flow`. Update any custom form themes that reference the old block names.

0.3.1
-----
* Add support for Symfony 8.0

0.3.0
-----
* Add support for grouping and nested steps in `FormFlowType`
Expand Down
14 changes: 14 additions & 0 deletions src/Form/Flow/AbstractButtonFlowType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Yceruto\FormFlowBundle\Form\Flow;

use Symfony\Component\Form\AbstractType;
use Yceruto\FormFlowBundle\Form\Flow\Type\ButtonFlowType;

abstract class AbstractButtonFlowType extends AbstractType implements ButtonFlowTypeInterface
{
public function getParent(): string
{
return ButtonFlowType::class;
}
}
14 changes: 0 additions & 14 deletions src/Form/Flow/AbstractFlowButtonType.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* A button that submits the form and handles an action.

*/
class FlowButton extends SubmitButton implements FlowButtonInterface
class ButtonFlow extends SubmitButton implements ButtonFlowInterface
{
private mixed $data = null;
private bool $handled = false;
Expand Down
16 changes: 16 additions & 0 deletions src/Form/Flow/ButtonFlowBuilder.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 ButtonFlow} instances.
*/
class ButtonFlowBuilder extends ButtonBuilder
{
public function getForm(): ButtonFlow
{
return new ButtonFlow($this->getFormConfig());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Symfony\Component\Form\ClickableInterface;
use Symfony\Component\Form\FormInterface;

interface FlowButtonInterface extends FormInterface, ClickableInterface
interface ButtonFlowInterface extends FormInterface, ClickableInterface
{
/**
* Executes the callable handler.
Expand Down
12 changes: 12 additions & 0 deletions src/Form/Flow/ButtonFlowTypeInterface.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 ButtonFlow} instance.
*/
interface ButtonFlowTypeInterface extends FormTypeInterface
{
}
16 changes: 0 additions & 16 deletions src/Form/Flow/FlowButtonBuilder.php

This file was deleted.

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

This file was deleted.

14 changes: 7 additions & 7 deletions src/Form/Flow/FormFlow.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
*/
class FormFlow extends Form implements FormFlowInterface
{
private ?FlowButtonInterface $clickedFlowButton = null;
private ?ButtonFlowInterface $clickedFlowButton = null;
private bool $finished = false;

public function __construct(
private readonly FormFlowConfigInterface $config,
private FlowCursor $cursor,
private FormFlowCursor $cursor,
) {
parent::__construct($config);
}
Expand Down Expand Up @@ -74,14 +74,14 @@ public function movePrevious(?string $step = null): void
return;
}

if (!$this->move(static fn (FlowCursor $cursor) => $cursor->getPreviousStep())) {
if (!$this->move(static fn (FormFlowCursor $cursor) => $cursor->getPreviousStep())) {
throw new RuntimeException('Cannot determine previous step.');
}
}

public function moveNext(): void
{
if (!$this->move(static fn (FlowCursor $cursor) => $cursor->getNextStep())) {
if (!$this->move(static fn (FormFlowCursor $cursor) => $cursor->getNextStep())) {
throw new RuntimeException('Cannot determine next step.');
}
}
Expand All @@ -108,7 +108,7 @@ public function getStepForm(): static
return $this->newStepForm();
}

public function getCursor(): FlowCursor
public function getCursor(): FormFlowCursor
{
return $this->cursor;
}
Expand All @@ -123,7 +123,7 @@ public function isFinished(): bool
return $this->finished;
}

public function getClickedButton(): FlowButtonInterface|FormInterface|ClickableInterface|null
public function getClickedButton(): ButtonFlowInterface|FormInterface|ClickableInterface|null
{
return parent::getClickedButton() ?? $this->clickedFlowButton;
}
Expand All @@ -149,7 +149,7 @@ private function setClickedFlowButton(mixed $submittedData, FormInterface $form)
continue;
}

if (!$child instanceof FlowButtonInterface) {
if (!$child instanceof ButtonFlowInterface) {
continue;
}

Expand Down
24 changes: 12 additions & 12 deletions src/Form/Flow/FormFlowBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,38 @@
class FormFlowBuilder extends FormBuilder implements FormFlowBuilderInterface
{
/**
* @var array<string, FlowStepBuilderInterface>
* @var array<string, StepFlowBuilderConfigInterface>
*/
private array $steps = [];
private array $initialOptions = [];
private DataStorageInterface $dataStorage;
private StepAccessorInterface $stepAccessor;

public function createStepGroup(string $name): FlowStepBuilderInterface
public function createStepGroup(string $name): StepFlowBuilderConfigInterface
{
if ($this->locked) {
throw new BadMethodCallException('FormFlowBuilder methods cannot be accessed anymore once the builder is turned into a FormFlowConfigInterface instance.');
}

return (new FlowStepBuilder($name))->setGroup(true);
return (new StepFlowBuilder($name))->setGroup(true);
}

public function createStep(string $name, string $type = FormType::class, array $options = []): FlowStepBuilderInterface
public function createStep(string $name, string $type = FormType::class, array $options = []): StepFlowBuilderConfigInterface
{
if ($this->locked) {
throw new BadMethodCallException('FormFlowBuilder methods cannot be accessed anymore once the builder is turned into a FormFlowConfigInterface instance.');
}

return new FlowStepBuilder($name, $type, $options);
return new StepFlowBuilder($name, $type, $options);
}

public function addStep(FlowStepBuilderInterface|string $name, string $type = FormType::class, array $options = [], ?callable $skip = null, int $priority = 0): static
public function addStep(StepFlowBuilderConfigInterface|string $name, string $type = FormType::class, array $options = [], ?callable $skip = null, int $priority = 0): static
{
if ($this->locked) {
throw new BadMethodCallException('FormFlowBuilder methods cannot be accessed anymore once the builder is turned into a FormFlowConfigInterface instance.');
}

if ($name instanceof FlowStepBuilderInterface) {
if ($name instanceof StepFlowBuilderConfigInterface) {
$this->steps[$name->getName()] = $name;

return $this;
Expand Down Expand Up @@ -90,7 +90,7 @@ public function hasStep(string $name): bool
return false;
}

public function getStep(string $name): FlowStepBuilderInterface
public function getStep(string $name): StepFlowBuilderConfigInterface
{
if (isset($this->steps[$name])) {
return $this->steps[$name];
Expand Down Expand Up @@ -222,15 +222,15 @@ private function createFormFlow(): FormFlowInterface
throw new InvalidArgumentException('Steps not configured.');
}

uasort($this->steps, static fn (FlowStepBuilderInterface $a, FlowStepBuilderInterface $b) => $b->getPriority() <=> $a->getPriority());
uasort($this->steps, static fn (StepFlowBuilderConfigInterface $a, StepFlowBuilderConfigInterface $b) => $b->getPriority() <=> $a->getPriority());

$config = $this->getFormConfig();
$currentStep = $this->resolveCurrentStep();

$step = $this->getStep($currentStep);
$this->add($step->getName(), $step->getType(), $step->getOptions());

$cursor = new FlowCursor($config->getSteps(), $currentStep);
$cursor = new FormFlowCursor($config->getSteps(), $currentStep);
$this->pruneActionButtons($this, $cursor);

return new FormFlow($config, $cursor);
Expand Down Expand Up @@ -273,7 +273,7 @@ private function resolveFirstStep(?array $steps = null): string
throw new LogicException('No navigable step found. All steps are groups or skipped.');
}

private function pruneActionButtons(FormBuilderInterface $builder, FlowCursor $cursor): void
private function pruneActionButtons(FormBuilderInterface $builder, FormFlowCursor $cursor): void
{
foreach ($builder->all() as $child) {
if ($child->count() > 0) {
Expand All @@ -282,7 +282,7 @@ private function pruneActionButtons(FormBuilderInterface $builder, FlowCursor $c
continue;
}

if (!$child instanceof FlowButtonBuilder || !\is_callable($include = $child->getOption('include_if'))) {
if (!$child instanceof ButtonFlowBuilder || !\is_callable($include = $child->getOption('include_if'))) {
continue;
}

Expand Down
10 changes: 5 additions & 5 deletions src/Form/Flow/FormFlowBuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ interface FormFlowBuilderInterface extends FormBuilderInterface, FormFlowConfigI
/**
* Creates a new step builder marked as a group.
*/
public function createStepGroup(string $name): FlowStepBuilderInterface;
public function createStepGroup(string $name): StepFlowBuilderConfigInterface;

/**
* Creates a new step builder.
*/
public function createStep(string $name, string $type = FormType::class, array $options = []): FlowStepBuilderInterface;
public function createStep(string $name, string $type = FormType::class, array $options = []): StepFlowBuilderConfigInterface;

/**
* Adds a step to the form flow.
*/
public function addStep(FlowStepBuilderInterface|string $name, string $type = FormType::class, array $options = [], ?callable $skip = null, int $priority = 0): static;
public function addStep(StepFlowBuilderConfigInterface|string $name, string $type = FormType::class, array $options = [], ?callable $skip = null, int $priority = 0): static;

/**
* Removes a step from the form flow.
Expand All @@ -35,12 +35,12 @@ public function removeStep(string $name): static;
/**
* Returns a step builder by name.
*/
public function getStep(string $name): FlowStepBuilderInterface;
public function getStep(string $name): StepFlowBuilderConfigInterface;

/**
* Returns all step builders.
*
* @return array<string, FlowStepBuilderInterface>
* @return array<string, StepFlowBuilderConfigInterface>
*/
public function getSteps(): array;

Expand Down
4 changes: 2 additions & 2 deletions src/Form/Flow/FormFlowConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ public function hasStep(string $name): bool;
/**
* Returns the step with the given name.
*/
public function getStep(string $name): FlowStepConfigInterface;
public function getStep(string $name): StepFlowConfigInterface;

/**
* Returns all steps.
*
* @return array<string, FlowStepConfigInterface>
* @return array<string, StepFlowConfigInterface>
*/
public function getSteps(): array;

Expand Down
Loading
Loading