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

0.2.3
-----
* Add `buildViewFlow()` and `finishViewFlow` methods to `FormFlowTypeInterface`

0.2.2
-----
* Add `AbstractFlowButtonType` to simplify button type creation
Expand Down
24 changes: 24 additions & 0 deletions src/Form/Flow/AbstractFlowType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Yceruto\FormFlowBundle\Form\Flow\Type\FormFlowType;

abstract class AbstractFlowType extends AbstractType implements FormFlowTypeInterface
Expand All @@ -15,10 +17,32 @@ final public function buildForm(FormBuilderInterface $builder, array $options):
$this->buildFormFlow($builder, $options);
}

final public function buildView(FormView $view, FormInterface $form, array $options): void
{
\assert($form instanceof FormFlowInterface);

$this->buildViewFlow($view, $form, $options);
}

final public function finishView(FormView $view, FormInterface $form, array $options): void
{
\assert($form instanceof FormFlowInterface);

$this->finishViewFlow($view, $form, $options);
}

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

public function buildViewFlow(FormView $view, FormFlowInterface $form, array $options): void
{
}

public function finishViewFlow(FormView $view, FormFlowInterface $form, array $options): void
{
}

public function getParent(): string
{
return FormFlowType::class;
Expand Down
39 changes: 39 additions & 0 deletions src/Form/Flow/FormFlowTypeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,50 @@
namespace Yceruto\FormFlowBundle\Form\Flow;

use Symfony\Component\Form\FormTypeInterface;
use Symfony\Component\Form\FormView;

/**
* A type that should be converted into a {@link FormFlow} instance.
*/
interface FormFlowTypeInterface extends FormTypeInterface
{
/**
* Builds the multistep form.
*
* This method is called for each multistep type. Type extensions can further
* modify the multistep form.
*
* @param array<string, mixed> $options
*/
public function buildFormFlow(FormFlowBuilderInterface $builder, array $options): void;

/**
* Builds the multistep form view.
*
* This method is called for each multistep type. Type extensions can further
* modify the view.
*
* A view of a multistep form is built before the views of the child forms are built.
* This means that you cannot access child views in this method. If you need
* to do so, move your logic to {@link finishViewFlow()} instead.
*
* @param array<string, mixed> $options
*/
public function buildViewFlow(FormView $view, FormFlowInterface $form, array $options): void;

/**
* Finishes the multistep form view.
*
* This method gets called for each multistep type. Type extensions can further
* modify the view.
*
* When this method is called, views of the multistep form's children have already
* been built and finished and can be accessed. You should only implement
* such logic in this method that actually accesses child views. For everything
* else you are recommended to implement {@link buildViewFlow()} instead.
*
* @param array<string, mixed> $options
*/
public function finishViewFlow(FormView $view, FormFlowInterface $form, array $options): void;

}
5 changes: 1 addition & 4 deletions src/Form/Flow/Type/FormFlowType.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\Exception\MissingOptionsException;
use Symfony\Component\OptionsResolver\Options;
Expand Down Expand Up @@ -42,10 +41,8 @@ public function buildFormFlow(FormFlowBuilderInterface $builder, array $options)
$builder->addEventListener(FormEvents::PRE_SUBMIT, $this->onPreSubmit(...), -100);
}

public function buildView(FormView $view, FormInterface $form, array $options): void
public function buildViewFlow(FormView $view, FormFlowInterface $form, array $options): void
{
\assert($form instanceof FormFlowInterface);

$view->vars['cursor'] = $cursor = $form->getCursor();

$index = 0;
Expand Down