Skip to content

Commit e3042b6

Browse files
HeahDudenicolas-grekas
authored andcommittedAug 2, 2023
[Form][DX] Use logical ordering for type and extension methods
1 parent 45b1b17 commit e3042b6

4 files changed

+44
-41
lines changed
 

‎AbstractType.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -21,46 +21,46 @@
2121
abstract class AbstractType implements FormTypeInterface
2222
{
2323
/**
24-
* @return void
24+
* @return string|null
2525
*/
26-
public function buildForm(FormBuilderInterface $builder, array $options)
26+
public function getParent()
2727
{
28+
return FormType::class;
2829
}
2930

3031
/**
3132
* @return void
3233
*/
33-
public function buildView(FormView $view, FormInterface $form, array $options)
34+
public function configureOptions(OptionsResolver $resolver)
3435
{
3536
}
3637

3738
/**
3839
* @return void
3940
*/
40-
public function finishView(FormView $view, FormInterface $form, array $options)
41+
public function buildForm(FormBuilderInterface $builder, array $options)
4142
{
4243
}
4344

4445
/**
4546
* @return void
4647
*/
47-
public function configureOptions(OptionsResolver $resolver)
48+
public function buildView(FormView $view, FormInterface $form, array $options)
4849
{
4950
}
5051

5152
/**
52-
* @return string
53+
* @return void
5354
*/
54-
public function getBlockPrefix()
55+
public function finishView(FormView $view, FormInterface $form, array $options)
5556
{
56-
return StringUtil::fqcnToBlockPrefix(static::class) ?: '';
5757
}
5858

5959
/**
60-
* @return string|null
60+
* @return string
6161
*/
62-
public function getParent()
62+
public function getBlockPrefix()
6363
{
64-
return FormType::class;
64+
return StringUtil::fqcnToBlockPrefix(static::class) ?: '';
6565
}
6666
}

‎AbstractTypeExtension.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,28 @@ abstract class AbstractTypeExtension implements FormTypeExtensionInterface
2121
/**
2222
* @return void
2323
*/
24-
public function buildForm(FormBuilderInterface $builder, array $options)
24+
public function configureOptions(OptionsResolver $resolver)
2525
{
2626
}
2727

2828
/**
2929
* @return void
3030
*/
31-
public function buildView(FormView $view, FormInterface $form, array $options)
31+
public function buildForm(FormBuilderInterface $builder, array $options)
3232
{
3333
}
3434

3535
/**
3636
* @return void
3737
*/
38-
public function finishView(FormView $view, FormInterface $form, array $options)
38+
public function buildView(FormView $view, FormInterface $form, array $options)
3939
{
4040
}
4141

4242
/**
4343
* @return void
4444
*/
45-
public function configureOptions(OptionsResolver $resolver)
45+
public function finishView(FormView $view, FormInterface $form, array $options)
4646
{
4747
}
4848
}

‎FormTypeExtensionInterface.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@
1818
*/
1919
interface FormTypeExtensionInterface
2020
{
21+
/**
22+
* Gets the extended types.
23+
*
24+
* @return string[]
25+
*/
26+
public static function getExtendedTypes(): iterable;
27+
28+
/**
29+
* @return void
30+
*/
31+
public function configureOptions(OptionsResolver $resolver);
32+
2133
/**
2234
* Builds the form.
2335
*
@@ -59,16 +71,4 @@ public function buildView(FormView $view, FormInterface $form, array $options);
5971
* @see FormTypeInterface::finishView()
6072
*/
6173
public function finishView(FormView $view, FormInterface $form, array $options);
62-
63-
/**
64-
* @return void
65-
*/
66-
public function configureOptions(OptionsResolver $resolver);
67-
68-
/**
69-
* Gets the extended types.
70-
*
71-
* @return string[]
72-
*/
73-
public static function getExtendedTypes(): iterable;
7474
}

‎FormTypeInterface.php

+17-14
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@
1818
*/
1919
interface FormTypeInterface
2020
{
21+
/**
22+
* Returns the name of the parent type.
23+
*
24+
* The parent type and its extensions will configure the form with the
25+
* following methods before the current implementation.
26+
*
27+
* @return string|null
28+
*/
29+
public function getParent();
30+
31+
/**
32+
* Configures the options for this type.
33+
*
34+
* @return void
35+
*/
36+
public function configureOptions(OptionsResolver $resolver);
37+
2138
/**
2239
* Builds the form.
2340
*
@@ -69,13 +86,6 @@ public function buildView(FormView $view, FormInterface $form, array $options);
6986
*/
7087
public function finishView(FormView $view, FormInterface $form, array $options);
7188

72-
/**
73-
* Configures the options for this type.
74-
*
75-
* @return void
76-
*/
77-
public function configureOptions(OptionsResolver $resolver);
78-
7989
/**
8090
* Returns the prefix of the template block name for this type.
8191
*
@@ -85,11 +95,4 @@ public function configureOptions(OptionsResolver $resolver);
8595
* @return string
8696
*/
8797
public function getBlockPrefix();
88-
89-
/**
90-
* Returns the name of the parent type.
91-
*
92-
* @return string|null
93-
*/
94-
public function getParent();
9598
}

0 commit comments

Comments
 (0)
Please sign in to comment.