Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[FrameworkBundle] add support for prioritizing form type extension tags#19790
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
| $definition->replaceArgument(2,$typeExtensions); | ||
| $sortedTypeExtensions = []; | ||
| foreach ($typeExtensionsas$extendedType =>$extensionsWithPriority) { | ||
| usort($extensionsWithPriority,function (array$a,array$b) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
You can use thehttps://github.com/symfony/symfony/blob/master/src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php, it will do the job for you :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Ah good to know 😊
But that would globally sort all form extensions. We only want to sort per extended type though? 😉
79d2af6 to7d7c957Comparedmaicher commentedAug 30, 2016
Actually I just realized that the http://www.php.net/manual/en/function.usort.php
This means we would have to sort differently to be 100% sure there is no BC break? |
7d7c957 to3d0bda3Compareogizanagi commentedAug 30, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
What about using the |
dmaicher commentedAug 31, 2016
It seems that also |
HeahDude commentedAug 31, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@dmaicher There is no stable sorting by default either as it depends on the order of the services registration (which is not predictable unless using a custom pass, not sure it is worth it in that case though), and this is partially responsible for the issue you're trying to solve.
Currently form type extensions cannot rely on other extensions, at least handling priorities will solve this. |
dmaicher commentedAug 31, 2016
@HeahDude But as you said currently without priorities it depends on the order of service registration. If we introduce a non-stable sorting then it might be a BC break though as the order of service registration is not 100% guaranteed to be used anymore for the form extensions (when all extensions have equal priority 0)? |
HeahDude commentedAug 31, 2016
What I'm saying is that this order is not reliable already, so it is an acceptable BC break IMO because it does not change anything unless some extensions rely on each other, which is buggy right now unless using your new feature :) |
dmaicher commentedAug 31, 2016
@HeahDude Ok now I see what you mean 😊 If this "BC break" is acceptable then I can surely change it 😄 Other opinions on that? |
| $sortedTypeExtensions =array(); | ||
| foreach ($typeExtensionsas$extendedType =>$extensionsWithPriority) { | ||
| usort($extensionsWithPriority,function (array$a,array$b) { | ||
| return$a[1] >$b[1] ? -1 :1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
this never returns0, strange, why that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Changed in favour of\SplPriorityQueue now 😉
linaori commentedAug 31, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
You can still usethe trait as inspiration and maybe play around with the existing function. |
c982f84 tof9f8b57Comparedmaicher commentedAug 31, 2016
I changed it to use If all agree this feature is useful as is I could prepare a PR for the docs? |
bb0e184 to7570bbbComparefabpot commentedAug 31, 2016
Relying on the order is it really something we want to support? Do we have enough real-world use cases? Nobody ever had this issue in the last 5 years, so I'm wondering if we really need to support this. |
HeahDude commentedAug 31, 2016
Form type extensions are meant to decouple specific configuration, thus may add options to resolve. So on one hand I agree, this is maybe covering edge cases where one need to handle that kind of option globally. Actually resolving the form configuration is why we need this composite pattern, and the process works well because it is mainly based on inheritance which do keep an order, so if we can support it for extensions too, I guess we should. Good things:
Bad things:
Anyway thank you@dmaicher for proposing this feature. |
dmaicher commentedSep 1, 2016
I would also agree with@HeahDude. I don't see any disadvantages of having this really small (+10, -3 LOC excluding tests) feature. Sure maybe not so many people will use it but currently the behaviour is a bit unpredictable for the order of form type extensions which is quite bad imho 😢 |
HeahDude commentedSep 3, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@dmaicher After re-reading this, I still think you should use the trait and change onlythis line, you can then keep the same logic as before to handle the indexation by extended type but you'll create the priority job only once which will also use only one instance one I think that is is a good thing too because in the future if there is some issue about extensions overriding each other we will be able to solve it thanks to this feature. |
dmaicher commentedSep 4, 2016
with this foreach ($this->findAndSortTaggedServices('form.type_extension',$container)as$reference) {...} I just have a sorted list of service But I think you are right about sorting all extensions globally though 😊 Might make more sense. |
ogizanagi commentedSep 4, 2016
@dmaicher : The |
7570bbb toab302dcCompareab302dc toe3aa701Compare| } | ||
| $tag =$serviceDefinition->getTag('form.type_extension'); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
this empty line is not needed :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
👍
e3aa701 toaac8a3fCompareHeahDude commentedSep 4, 2016
nicolas-grekas commentedSep 6, 2016
@dmaicher can you please update the CHANGELOG file of the component? |
aac8a3f toce051afComparedmaicher commentedSep 8, 2016
@nicolas-grekas done 😉 Let me know if I need to change anything else |
HeahDude commentedSep 8, 2016
@dmaicher Can you please update the description too (tests are passing now :) and submit a PR in the docs? Thanks again! |
dmaicher commentedSep 9, 2016
@HeahDude done 😉 |
| * @dataProvider addTaggedTypeExtensionsDataProvider | ||
| * | ||
| * @param array $extensions | ||
| * @param array $expectedRegisteredExtensions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
this phpdoc for params is needless
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Ok removing it 👍
HeahDude commentedSep 9, 2016
👍 Status: Reviewed |
ce051af toa3db5f0Comparefabpot commentedSep 14, 2016
Thank you@dmaicher. |
…pe extension tags (dmaicher)This PR was merged into the 3.2-dev branch.Discussion----------[FrameworkBundle] add support for prioritizing form type extension tags| Q | A| ------------- | ---| Branch? | "master"| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets |#19735| License | MIT| Doc PR |symfony/symfony-docs#6958This PR proposes to add support for `priority` on `form.type_extension` dependecyinjection tags to enable sorting/prioritizing form type extensions.Issue was mentioned here:#19735Commits-------a3db5f0 [FrameworkBundle] add support for prioritizing form type extension tags
…e extension tags (dmaicher)This PR was squashed before being merged into the master branch (closes#6958).Discussion----------[FrameworkBundle] add support for prioritizing form type extension tagsDoc PR forsymfony/symfony#19790Commits-------0e0bdc3 [FrameworkBundle] add support for prioritizing form type extension tags
chrisguitarguy commentedJan 4, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
A bit late to the party here, but I absolutely think this was a BC break. Seedunglas/DunglasAngularCsrfBundle#39 The entire bundle's csrf protection form extension is broken because it now loads before the core csrf extension -- it disables csrf on a form in favor of its own system only to have it re-enabled by the core extension which now loads later in 3.2. |
dmaicher commentedJan 4, 2017
@chrisguitarguy this should have been fixed with#20995 |
chrisguitarguy commentedJan 4, 2017
Great! Will have to downgrade to Symfony 3.1 until the next bugfix release of 3.2, though. |
Uh oh!
There was an error while loading.Please reload this page.
This PR proposes to add support for
priorityonform.type_extensiondependecyinjection tags to enable sorting/prioritizing form type extensions.Issue was mentioned here:#19735