8000 [Form] Allow to extend multiple form types · Issue #9507 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[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

Closed
egeloen opened this issue Nov 14, 2013 · 9 comments
Closed

[Form] Allow to extend multiple form types #9507

egeloen opened this issue Nov 14, 2013 · 9 comments

Comments

@egeloen
Copy link
egeloen commented Nov 14, 2013

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 uses form 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 the FormType 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?

@stof
Copy link
Member
stof commented Nov 14, 2013

It could indeed make sense to allow extending several form types in a type extension. What do you think @bschussek ?

@sstok
Copy link
Contributor
sstok commented Nov 16, 2013

My only concern is when a type-extension is applied multiple times in the building process.

my-type extends text which extends form

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).

@egeloen
Copy link
Author
egeloen commented Jan 25, 2014

@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.

@CSchulz
Copy link
CSchulz commented Apr 7, 2014

I want to have a similar inheritance feature.

group extends base which extends form

Text should be our base form type to allow extending with some extensions and f.e. group is our specific form type.
So I want to extend the base and get the fields by the extension for group, too.
At the moment it only works if I register the extension for group.

@sstok
So I don't understand how the type-extension can be applied multiple times?

@koemeet
Copy link
koemeet commented Nov 9, 2014

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.

@egeloen
Copy link
Author
egeloen commented Nov 9, 2014

This is what I already do here but it's a little bit frustrating to have to define several classes just for that...

@webmozart
Copy link
Contributor

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.

@MatTheCat
Copy link
Contributor

@webmozart is there a better way now?

@xabbuh
Copy link
Member
xabbuh commented Oct 10, 2018

this will be part of Symfony 4.2 as #24530 has been merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants
0