Skip to content

Commit

Permalink
[Form][DX] Use logical ordering for type and extension methods
Browse files Browse the repository at this point in the history
  • Loading branch information
HeahDude authored and nicolas-grekas committed Aug 2, 2023
1 parent 45b1b17 commit e3042b6
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 41 deletions.
22 changes: 11 additions & 11 deletions AbstractType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) ?: '';
}
}
8 changes: 4 additions & 4 deletions AbstractTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
}
24 changes: 12 additions & 12 deletions FormTypeExtensionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
}
31 changes: 17 additions & 14 deletions FormTypeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand All @@ -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();
}

0 comments on commit e3042b6

Please sign in to comment.