Skip to content

Commit 62d2b18

Browse files
authored
Merge pull request #6 from yceruto/add_form_flow_type_methods
add buildViewFlow and finishViewFlow methods to FormFlowTypeInterface
2 parents 0e4c8cd + f86c0d7 commit 62d2b18

File tree

4 files changed

+68
-4
lines changed

4 files changed

+68
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
CHANGELOG
22
=========
33

4+
0.2.3
5+
-----
6+
* Add `buildViewFlow()` and `finishViewFlow` methods to `FormFlowTypeInterface`
7+
48
0.2.2
59
-----
610
* Add `AbstractFlowButtonType` to simplify button type creation

src/Form/Flow/AbstractFlowType.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use Symfony\Component\Form\AbstractType;
66
use Symfony\Component\Form\FormBuilderInterface;
7+
use Symfony\Component\Form\FormInterface;
8+
use Symfony\Component\Form\FormView;
79
use Yceruto\FormFlowBundle\Form\Flow\Type\FormFlowType;
810

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

20+
final public function buildView(FormView $view, FormInterface $form, array $options): void
21+
{
22+
\assert($form instanceof FormFlowInterface);
23+
24+
$this->buildViewFlow($view, $form, $options);
25+
}
26+
27+
final public function finishView(FormView $view, FormInterface $form, array $options): void
28+
{
29+
\assert($form instanceof FormFlowInterface);
30+
31+
$this->finishViewFlow($view, $form, $options);
32+
}
33+
1834
public function buildFormFlow(FormFlowBuilderInterface $builder, array $options): void
1935
{
2036
}
2137

38+
public function buildViewFlow(FormView $view, FormFlowInterface $form, array $options): void
39+
{
40+
}
41+
42+
public function finishViewFlow(FormView $view, FormFlowInterface $form, array $options): void
43+
{
44+
}
45+
2246
public function getParent(): string
2347
{
2448
return FormFlowType::class;

src/Form/Flow/FormFlowTypeInterface.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,50 @@
33
namespace Yceruto\FormFlowBundle\Form\Flow;
44

55
use Symfony\Component\Form\FormTypeInterface;
6+
use Symfony\Component\Form\FormView;
67

78
/**
89
* A type that should be converted into a {@link FormFlow} instance.
910
*/
1011
interface FormFlowTypeInterface extends FormTypeInterface
1112
{
13+
/**
14+
* Builds the multistep form.
15+
*
16+
* This method is called for each multistep type. Type extensions can further
17+
* modify the multistep form.
18+
*
19+
* @param array<string, mixed> $options
20+
*/
1221
public function buildFormFlow(FormFlowBuilderInterface $builder, array $options): void;
22+
23+
/**
24+
* Builds the multistep form view.
25+
*
26+
* This method is called for each multistep type. Type extensions can further
27+
* modify the view.
28+
*
29+
* A view of a multistep form is built before the views of the child forms are built.
30+
* This means that you cannot access child views in this method. If you need
31+
* to do so, move your logic to {@link finishViewFlow()} instead.
32+
*
33+
* @param array<string, mixed> $options
34+
*/
35+
public function buildViewFlow(FormView $view, FormFlowInterface $form, array $options): void;
36+
37+
/**
38+
* Finishes the multistep form view.
39+
*
40+
* This method gets called for each multistep type. Type extensions can further
41+
* modify the view.
42+
*
43+
* When this method is called, views of the multistep form's children have already
44+
* been built and finished and can be accessed. You should only implement
45+
* such logic in this method that actually accesses child views. For everything
46+
* else you are recommended to implement {@link buildViewFlow()} instead.
47+
*
48+
* @param array<string, mixed> $options
49+
*/
50+
public function finishViewFlow(FormView $view, FormFlowInterface $form, array $options): void;
51+
1352
}

src/Form/Flow/Type/FormFlowType.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Symfony\Component\Form\Extension\Core\Type\FormType;
66
use Symfony\Component\Form\FormEvent;
77
use Symfony\Component\Form\FormEvents;
8-
use Symfony\Component\Form\FormInterface;
98
use Symfony\Component\Form\FormView;
109
use Symfony\Component\OptionsResolver\Exception\MissingOptionsException;
1110
use Symfony\Component\OptionsResolver\Options;
@@ -42,10 +41,8 @@ public function buildFormFlow(FormFlowBuilderInterface $builder, array $options)
4241
$builder->addEventListener(FormEvents::PRE_SUBMIT, $this->onPreSubmit(...), -100);
4342
}
4443

45-
public function buildView(FormView $view, FormInterface $form, array $options): void
44+
public function buildViewFlow(FormView $view, FormFlowInterface $form, array $options): void
4645
{
47-
\assert($form instanceof FormFlowInterface);
48-
4946
$view->vars['cursor'] = $cursor = $form->getCursor();
5047

5148
$index = 0;

0 commit comments

Comments
 (0)