Skip to content

[3.0] [Form] Added the new getBlockPrefix() method to the ResolvedFormTypeInterface #16200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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: 1 addition & 3 deletions src/Symfony/Component/Form/ResolvedFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ public function __construct(FormTypeInterface $innerType, array $typeExtensions
}

/**
* Returns the prefix of the template block name for this type.
*
* @return string The prefix of the template block name
* {@inheritdoc}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is wrong as ResolvedFormTypeInterface does not define a getBlockPrefix. So either the method must be added to that interface as well. Or the public method should be removed from ResolvedFormType. I don't see why we need that public method on the resolved type as one can access it easily through getInnerType

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getName was part of the ResolvedFormTypeInterface: https://github.com/symfony/form/blob/2.8/ResolvedFormTypeInterface.php#L23-L28 I think it makes much sense to make getBlockPrefix part of the interface in 3.0

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be removed. I don't see the point of having this method in the resolved type as it must equal the inner one. So overwriting it makes no sense either.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if we remove it, we should do so in 2.8. @webmozart what is the point of having a getBlockPrefix on the ResolvedFormType?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping @webmozart

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's just merge this as is?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add the method to ResolvedFormTypeInterface also to respect the LoD. The method is used in https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Extension/Core/Type/BaseType.php#L80.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@webmozart why not simply call $type->getInnerType()->getBlockPrefix() there? It seems strange to me to offer two ways to do the same thing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @Tobion if that's the only reason to have this method in the interface.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My argument can be found in #16749. ResolvedFormType was always supposed to have all methods of FormType. getInnerType() exists for edge cases where you want to know by which actual class a form type is backed.

*/
public function getBlockPrefix()
{
Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Component/Form/ResolvedFormTypeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ interface ResolvedFormTypeInterface
*/
public function getParent();

/**
* Returns the prefix of the template block name for this type.
*
* The block prefix defaults to the underscored short class name with
* the "Type" suffix removed (e.g. "UserProfileType" => "user_profile").
*
* @return string The prefix of the template block name
*/
public function getBlockPrefix();

/**
* Returns the wrapped form type.
*
Expand Down