-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Ability to extend multiple form types with one type extension #27906
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
I personally have never needed it, but I guess there could be a good reason to do it. Btw, there is another alternative to achieve it #9507 (comment):
|
The issue is not critical yes, means it is not worth working on a bc layer for itself. IMHO the use case is legit, and modifying the interface already to handle auto configuration is a good opportunity to support it. Abstract class and trait can be used currently yes, but I never saw that in action either. However I did see some Anyway, having a clean and self explicit way to do it will prevent some trouble figuring out how this can be achieved and how ugly this can get. |
In order to be able to evaluate this proposal better, could you please share with us some real-world examples where extending multiple form types at the same time would be needed? Thanks! |
I can imagine a real example without having the need to do something like that yet. We usually make a text type extension in our application to add some options that will trigger some normalizers on submission. That's cool because all types that are a child of Here is the scenario. Now we install a new dependency that comes with a type which does not extend Currently we need to:
With such new feature it's just one line to declare another type class in the static method. |
@HeahDude I'm afraid your example is still a theoretical scenario. We need real-world examples where this feature would have been nice to have. I don't use the Form component, but I know that you and others use it a lot ... so, have you ever wished this feature existed to solve a real problem? Thanks! |
When I made #25582, I introduced a new |
More than that now with Symfony 4.1 I am always using |
Sometimes both |
…xabbuh) This PR was merged into the 4.2-dev branch. Discussion ---------- [Form] simplify the form type extension registration | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #22833, #27906 | License | MIT | Doc PR | Commits ------- 6a1d4c5 simplify the form type extension registration
Currently, it is only possible to extend a single form type (and all its children) with a single form type extension. If you want to add an additional option to, for example,
TextType
andChoiceType
you will either have to create two extension classes or create an extension for the baseFormType
and thus adding the option to most other form types too.@HeahDude and me discovered that we need to discuss if we want to support these uses cases in Form component before we can make a final decision on the implementation in #24530. Otherwise, we risk to deprecate the
getExtendedType()
method of theFormTypeExtensionInterface
in favour of a solution which would then in turn be deprecated again in one of the next minor releases just to support the extension of multiple form types. That wouldn't be good DX-wise.The text was updated successfully, but these errors were encountered: