From e3042b6844a7a29ec2d6afeccc87d8230b6da5cd Mon Sep 17 00:00:00 2001 From: Jules Pietri Date: Thu, 20 Jul 2023 13:12:56 +0200 Subject: [PATCH] [Form][DX] Use logical ordering for type and extension methods --- AbstractType.php | 22 +++++++++++----------- AbstractTypeExtension.php | 8 ++++---- FormTypeExtensionInterface.php | 24 ++++++++++++------------ FormTypeInterface.php | 31 +++++++++++++++++-------------- 4 files changed, 44 insertions(+), 41 deletions(-) diff --git a/AbstractType.php b/AbstractType.php index ad4b19569..8fffa379d 100644 --- a/AbstractType.php +++ b/AbstractType.php @@ -21,46 +21,46 @@ abstract class AbstractType implements FormTypeInterface { /** - * @return void + * @return string|null */ - public function buildForm(FormBuilderInterface $builder, array $options) + public function getParent() { + return FormType::class; } /** * @return void */ - public function buildView(FormView $view, FormInterface $form, array $options) + public function configureOptions(OptionsResolver $resolver) { } /** * @return void */ - public function finishView(FormView $view, FormInterface $form, array $options) + public function buildForm(FormBuilderInterface $builder, array $options) { } /** * @return void */ - public function configureOptions(OptionsResolver $resolver) + public function buildView(FormView $view, FormInterface $form, array $options) { } /** - * @return string + * @return void */ - public function getBlockPrefix() + public function finishView(FormView $view, FormInterface $form, array $options) { - return StringUtil::fqcnToBlockPrefix(static::class) ?: ''; } /** - * @return string|null + * @return string */ - public function getParent() + public function getBlockPrefix() { - return FormType::class; + return StringUtil::fqcnToBlockPrefix(static::class) ?: ''; } } diff --git a/AbstractTypeExtension.php b/AbstractTypeExtension.php index 422f28bf3..1956bd00a 100644 --- a/AbstractTypeExtension.php +++ b/AbstractTypeExtension.php @@ -21,28 +21,28 @@ abstract class AbstractTypeExtension implements FormTypeExtensionInterface /** * @return void */ - public function buildForm(FormBuilderInterface $builder, array $options) + public function configureOptions(OptionsResolver $resolver) { } /** * @return void */ - public function buildView(FormView $view, FormInterface $form, array $options) + public function buildForm(FormBuilderInterface $builder, array $options) { } /** * @return void */ - public function finishView(FormView $view, FormInterface $form, array $options) + public function buildView(FormView $view, FormInterface $form, array $options) { } /** * @return void */ - public function configureOptions(OptionsResolver $resolver) + public function finishView(FormView $view, FormInterface $form, array $options) { } } diff --git a/FormTypeExtensionInterface.php b/FormTypeExtensionInterface.php index 193783451..ae76457cd 100644 --- a/FormTypeExtensionInterface.php +++ b/FormTypeExtensionInterface.php @@ -18,6 +18,18 @@ */ interface FormTypeExtensionInterface { + /** + * Gets the extended types. + * + * @return string[] + */ + public static function getExtendedTypes(): iterable; + + /** + * @return void + */ + public function configureOptions(OptionsResolver $resolver); + /** * Builds the form. * @@ -59,16 +71,4 @@ public function buildView(FormView $view, FormInterface $form, array $options); * @see FormTypeInterface::finishView() */ public function finishView(FormView $view, FormInterface $form, array $options); - - /** - * @return void - */ - public function configureOptions(OptionsResolver $resolver); - - /** - * Gets the extended types. - * - * @return string[] - */ - public static function getExtendedTypes(): iterable; } diff --git a/FormTypeInterface.php b/FormTypeInterface.php index 0c586d3f7..2bc9f7711 100644 --- a/FormTypeInterface.php +++ b/FormTypeInterface.php @@ -18,6 +18,23 @@ */ interface FormTypeInterface { + /** + * Returns the name of the parent type. + * + * The parent type and its extensions will configure the form with the + * following methods before the current implementation. + * + * @return string|null + */ + public function getParent(); + + /** + * Configures the options for this type. + * + * @return void + */ + public function configureOptions(OptionsResolver $resolver); + /** * Builds the form. * @@ -69,13 +86,6 @@ public function buildView(FormView $view, FormInterface $form, array $options); */ public function finishView(FormView $view, FormInterface $form, array $options); - /** - * Configures the options for this type. - * - * @return void - */ - public function configureOptions(OptionsResolver $resolver); - /** * Returns the prefix of the template block name for this type. * @@ -85,11 +95,4 @@ public function configureOptions(OptionsResolver $resolver); * @return string */ public function getBlockPrefix(); - - /** - * Returns the name of the parent type. - * - * @return string|null - */ - public function getParent(); }