Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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

Merged
fabpot merged 1 commit intosymfony:masterfromdmaicher:form-extension-priority
Sep 14, 2016

Conversation

@dmaicher
Copy link
Contributor

@dmaicherdmaicher commentedAug 30, 2016
edited
Loading

QA
Branch?"master"
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#19735
LicenseMIT
Doc PRsymfony/symfony-docs#6958

This PR proposes to add support forpriority onform.type_extension dependecyinjection tags to enable sorting/prioritizing form type extensions.

Issue was mentioned here:#19735

HeahDude, dragu, and ghasrfakhri reacted with hooray emoji
$definition->replaceArgument(2,$typeExtensions);
$sortedTypeExtensions = [];
foreach ($typeExtensionsas$extendedType =>$extensionsWithPriority) {
usort($extensionsWithPriority,function (array$a,array$b) {
Copy link
Contributor

@HeahDudeHeahDudeAug 30, 2016
edited
Loading

Choose a reason for hiding this comment

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

Copy link
ContributorAuthor

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? 😉

HeahDude reacted with thumbs up emoji
@dmaicherdmaicherforce-pushed theform-extension-priority branch 3 times, most recently from79d2af6 to7d7c957CompareAugust 30, 2016 20:02
@dmaicherdmaicher changed the titleadd support for prioritizing form type extension tags[Form] add support for prioritizing form type extension tagsAug 30, 2016
@dmaicher
Copy link
ContributorAuthor

Actually I just realized that theusort function is not stable :(

http://www.php.net/manual/en/function.usort.php

"If two members compare as equal, their relative order in the sorted array is undefined."

This means we would have to sort differently to be 100% sure there is no BC break?

@dmaicherdmaicher changed the title[Form] add support for prioritizing form type extension tags[FrameworkBundle] add support for prioritizing form type extension tagsAug 30, 2016
@dmaicherdmaicherforce-pushed theform-extension-priority branch from7d7c957 to3d0bda3CompareAugust 30, 2016 20:32
@ogizanagi
Copy link
Contributor

ogizanagi commentedAug 30, 2016
edited
Loading

What about using thePriorityTaggedServiceTrait ? (or at least a\SplPriorityQueue like other passes like theAddSecurityVotersPass orDecoratorServicePass ones ?)

@dmaicher
Copy link
ContributorAuthor

It seems that also\SplPriorityQueue will not preserve the initial order of elements if the priority is equal (meaning its not a "stable sort"):

http://php.net/manual/de/class.splpriorityqueue.php#117067

@HeahDude
Copy link
Contributor

HeahDude commentedAug 31, 2016
edited
Loading

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

I don't see why you shouldn't use the trait.

Currently form type extensions cannot rely on other extensions, at least handling priorities will solve this.

@dmaicher
Copy link
ContributorAuthor

@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
Copy link
Contributor

currently without priorities it depends on the order of service registration

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

ogizanagi and yceruto reacted with thumbs up emoji

@dmaicher
Copy link
ContributorAuthor

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

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?

Copy link
ContributorAuthor

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
Copy link
Contributor

linaori commentedAug 31, 2016
edited
Loading

You can still usethe trait as inspiration and maybe play around with the existing function.

@dmaicherdmaicherforce-pushed theform-extension-priority branch 2 times, most recently fromc982f84 tof9f8b57CompareAugust 31, 2016 17:03
@dmaicher
Copy link
ContributorAuthor

I changed it to use\SplPriorityQueue now 😉

If all agree this feature is useful as is I could prepare a PR for the docs?

@dmaicherdmaicherforce-pushed theform-extension-priority branch 2 times, most recently frombb0e184 to7570bbbCompareAugust 31, 2016 17:08
@fabpot
Copy link
Member

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
Copy link
Contributor

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.
But on the other hand, the logical solution is to use an extension and in such cases having a full control of the order has a significant importance, otherwise it's just unpredictable.

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:

  • DX: user is in full control (workaround from@javiereguiluz is good but not enough, and neither ismine, the option may be undefined andthrow an exception or implies todefine it first which is definitely not user friendly),
  • Perf: it is handled in the compiler pass so no runtime overhead,
  • Design: this is consistent with the composite pattern: options, form and view are resolved from the higher parent to lowest priority extension,

Bad things:

  • This is not a bug fix, so master only :troll face:

Anyway thank you@dmaicher for proposing this feature.

dragu, dmaicher, MacDada, and yceruto reacted with thumbs up emoji

@dmaicher
Copy link
ContributorAuthor

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
Copy link
Contributor

HeahDude commentedSep 3, 2016
edited
Loading

@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 oneSplPriorityQueue since anyway by default no extension will have a priority set (keeping the same old unpredictable behavior ;).

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
Copy link
ContributorAuthor

@HeahDude

with this

foreach ($this->findAndSortTaggedServices('form.type_extension',$container)as$reference) {...}

I just have a sorted list of serviceReference objects. How do I get theextended_type info then from the tags?

But I think you are right about sorting all extensions globally though 😊 Might make more sense.

@ogizanagi
Copy link
Contributor

@dmaicher : TheReference instance converted to string gives you the service id. Just get the definition back from it, and access the tags :)

}

$tag =$serviceDefinition->getTag('form.type_extension');

Copy link
Contributor

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

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

👍

@HeahDude
Copy link
Contributor

LGTM Thanks@dmaicher :)

So what the conclusion here? ping@symfony/deciders

@dmaicher If this is accepted you'll have to update the framework bundle changelog file as well.

dmaicher reacted with hooray emoji

@nicolas-grekas
Copy link
Member

@dmaicher can you please update the CHANGELOG file of the component?

@dmaicher
Copy link
ContributorAuthor

@nicolas-grekas done 😉 Let me know if I need to change anything else

@HeahDude
Copy link
Contributor

@dmaicher Can you please update the description too (tests are passing now :) and submit a PR in the docs? Thanks again!

@dmaicher
Copy link
ContributorAuthor

@HeahDude done 😉

* @dataProvider addTaggedTypeExtensionsDataProvider
*
* @param array $extensions
* @param array $expectedRegisteredExtensions
Copy link
Contributor

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

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Ok removing it 👍

@HeahDude
Copy link
Contributor

👍

Status: Reviewed

dragu reacted with hooray emoji

@fabpot
Copy link
Member

Thank you@dmaicher.

dragu reacted with thumbs up emoji

@fabpotfabpot merged commita3db5f0 intosymfony:masterSep 14, 2016
fabpot added a commit that referenced this pull requestSep 14, 2016
…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
xabbuh added a commit to symfony/symfony-docs that referenced this pull requestOct 26, 2016
…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
@fabpotfabpot mentioned this pull requestOct 27, 2016
@dmaicherdmaicher deleted the form-extension-priority branchDecember 20, 2016 18:08
@chrisguitarguy
Copy link
Contributor

chrisguitarguy commentedJan 4, 2017
edited
Loading

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
Copy link
ContributorAuthor

@chrisguitarguy this should have been fixed with#20995

@chrisguitarguy
Copy link
Contributor

Great! Will have to downgrade to Symfony 3.1 until the next bugfix release of 3.2, though.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

8 participants

@dmaicher@ogizanagi@HeahDude@linaori@fabpot@nicolas-grekas@chrisguitarguy@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp