-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Allow to extend multiple form types #9507
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
Comments
It could indeed make sense to allow extending several form types in a type extension. What do you think @bschussek ? |
My only concern is when a type-extension is applied multiple times in the building process.
With an extension extends both 'form' and 'text', this will make the extension be applied twice (once after form, and then after text) (which can have some annoying side effects). |
@bschussek @stof Do you see a way to prevent options collision? Anyway, more I think about this issue more I think it is maybe not needed as we can load multiple form type extensions in a single form extension. |
I want to have a similar inheritance feature.
Text should be our base form type to allow extending with some extensions and f.e. group is our specific form type. @sstok |
Isn't it better to make an abstract Extension class yourself and then create concrete Extension classes that utilizes this common functionaility from your abstract extension class? So you have DRY code but still have multiple form types use the same extension logic. |
This is what I already do here but it's a little bit frustrating to have to define several classes just for that... |
I agree that's it a bit stupid to have to define several classes to apply a type extension to multiple types. However, the type extension mechanism is already quite a mess and I'd rather not add more functionality to it anymore. In fact, I would like type extensions to be simplified in 3.0 or 4.0. So, since there is a solution that works right now (abstract type + subclasses) - even thought it's not the nicest one - I don't think this issue is critical. |
@webmozart is there a better way now? |
this will be part of Symfony 4.2 as #24530 has been merged |
Hey!
Before Symfony 2.3, all form types use the
FormType
as base type allowing us to easily override all form types via a form type extension which usesform
as parent extended type. Since Symfony 2.3, the button types have been introduced but they are a specific kind of types which don't use theFormType
as base form. Because of that, we need to create two form types extension if we want to override all form types (one for the form & an other for the button).IMO, since all types don't use the same base form (
FormType
), the form type extension should allow to override more than one type by returning a string (to maintain the BC) or an array of extended parent types. What do you think?The text was updated successfully, but these errors were encountered: