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

[Form] Do not ignore the choice groups for caching#29695

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

Conversation

@vudaltsov
Copy link
Contributor

@vudaltsovvudaltsov commentedDec 26, 2018
edited
Loading

QA
Branch?3.4
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed ticketsn/a
LicenseMIT
Doc PRn/a

While working on a different issue I suddenly came over a strange behaviour.

$builder    ->add('choice1', ChoiceType::class, ['choices' => ['a' =>'a','b' =>'b','c' =>'c',        ],'multiple' =>true,    ])    ->add('choice2', ChoiceType::class, ['choices' => ['ab' => ['a' =>'a','b' =>'b',            ],'c' =>'c',        ],'multiple' =>true,    ]);

The code above will result in two identical selects:

image

The reason for this is hash generation inSymfony\Component\Form\ChoiceList\Factory\CachingFactoryDecorator::createListFromChoices() — it does not take array structure into account. Seethe comment and the code below it.

The comment says that the same choice list should be returned for the same collection of choices no matter the structure. This is wrong, becauseChoiceListInterface has a methodgetStructuredValues() and thus a list instance cannot identified by a hash which does not take structure into account.

I propose a simple change that fixes this and allows for similar choice fields with different groupings.

ping@HeahDude

MoukrimKhouloud reacted with thumbs up emoji
Copy link
Contributor

@HeahDudeHeahDude left a comment

Choose a reason for hiding this comment

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

👍 for me. Thanks!

Ping@stof, I remember discussing this edge case with you in Berlin two years ago (the workaround being the use ofgroup_by option instead of relying on the structured values), it seems it's worth to fix the issue to simplify things in master.

@fabpot
Copy link
Member

Thank you@vudaltsov.

@fabpotfabpot merged commit9007911 intosymfony:3.4Jan 3, 2019
fabpot added a commit that referenced this pull requestJan 3, 2019
…sov)This PR was merged into the 3.4 branch.Discussion----------[Form] Do not ignore the choice groups for caching| Q             | A| ------------- | ---| Branch?       | 3.4| Bug fix?      | yes| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | n/a| License       | MIT| Doc PR        | n/aWhile working on a different issue I suddenly came over a strange behaviour.```php$builder    ->add('choice1', ChoiceType::class, [        'choices' => [            'a' => 'a',            'b' => 'b',            'c' => 'c',        ],        'multiple' => true,    ])    ->add('choice2', ChoiceType::class, [        'choices' => [            'ab' => [                'a' => 'a',                'b' => 'b',            ],            'c' => 'c',        ],        'multiple' => true,    ]);```The code above will result in two identical selects:![image](https://user-images.githubusercontent.com/2552865/50459865-b3e36980-0980-11e9-8f3d-17f9cfa9a7f8.png)The reason for this is hash generation in `Symfony\Component\Form\ChoiceList\Factory\CachingFactoryDecorator::createListFromChoices()` — it does not take array structure into account. See [the comment and the code below it](https://github.com/symfony/symfony/blob/7f46dfb1c4ce5e45a5f1918ad6223a3bbdd52a0b/src/Symfony/Component/Form/ChoiceList/Factory/CachingFactoryDecorator.php#L116).The comment says that the same choice list should be returned for the same collection of choices no matter the structure. This is wrong, because `ChoiceListInterface` has a method `getStructuredValues()` and thus a list instance cannot identified by a hash which does not take structure into account.I propose a simple change that fixes this and allows for similar choice fields with different groupings.ping@HeahDudeCommits-------9007911 Do not ignore the choice groups for caching
@vudaltsovvudaltsov deleted the form-choices-caching-factory-flattened branchJanuary 3, 2019 16:55
This was referencedJan 6, 2019
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot approved these changes

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

+1 more reviewer

@HeahDudeHeahDudeHeahDude approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

3.4

Development

Successfully merging this pull request may close these issues.

5 participants

@vudaltsov@fabpot@nicolas-grekas@HeahDude@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp