[2.8] [Form] Modified iterator_to_array's 2nd parameter to false in ViolationMapper#18747
Closed
issei-m wants to merge 2 commits intosymfony:2.8from
Closed
[2.8] [Form] Modified iterator_to_array's 2nd parameter to false in ViolationMapper#18747issei-m wants to merge 2 commits intosymfony:2.8from
issei-m wants to merge 2 commits intosymfony:2.8from
Conversation
36ff52e to
fb920b0
Compare
Contributor
Author
|
ping @alekitto @webmozart |
Contributor
|
Yes, you're right, elements are overwritten in the However, the fix was originally submitted to the 2.3 branch, probably that branch is affected from this bug too... |
Contributor
Author
Great! It's exactly what I want. I will fix soon.
Indeed. I'm also gonna fix target branch. |
8000
fb920b0 to
cf520b5
Compare
Contributor
Author
Contributor
Author
|
For 2.3: #18761 |
fabpot
added a commit
that referenced
this pull request
May 13, 2016
… false in ViolationMapper (issei-m) This PR was squashed before being merged into the 2.3 branch (closes #18761). Discussion ---------- [2.3] [Form] Modified iterator_to_array's 2nd parameter to false in ViolationMapper | Q | A | ------------- | --- | Branch? | 2.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a For #18747 Commits ------- 7101cab [2.3] [Form] Modified iterator_to_array's 2nd parameter to false in ViolationMapper
Member
|
Thank you @issei-m. |
fabpot
added a commit
that referenced
this pull request
May 13, 2016
… false in ViolationMapper (issei-m) This PR was submitted for the 2.8 branch but it was merged into the 2.7 branch instead (closes #18747). Discussion ---------- [2.8] [Form] Modified iterator_to_array's 2nd parameter to false in ViolationMapper | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a This bug was introduced in PR #17099. So does not represent in 2.8.2 or older. If we have the following structure form: ```php $builder = $formFactory->createBuilder(); $form = $builder ->add( $builder->create('person1_name', FormType::class, ['inherit_data' => true]) ->add('first', TextType::class, ['property_path' => '[person1_first_name]']) ->add('last', TextType::class, ['property_path' => '[person1_last_name]']) ) ->add( $builder->create('person2_name', FormType::class, ['inherit_data' => true]) ->add('first', TextType::class, ['property_path' => '[person2_first_name]']) ->add('last', TextType::class, ['property_path' => '[person2_last_name]']) ) ->getForm() ; ``` The following mapping for this form doesn't work correctly: ```php $mapper = new ViolationMapper(); $mapper->mapViolation(new ConstraintViolation('', '', [], null, 'data[person1_first_name]', null), $form); $form['person1_name']['first']->getErrors(); // empty $form->getErrors(); // The violation is mapped to here instead. ``` ## Cause Because ViolationMapper uses `iterator_to_array` in [here](https://github.com/symfony/symfony/blob/f29d46f29b91ea5c30699cf6bdb8e65545d1dd26/src/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationMapper.php#L165) to collect the sub forms. `person1_name` and `person2_name` enable `inherit_data` option. So ViolationMapper will attempt to collect the sub forms of root form like this: ```php [ 'first' => Form object, // root.person1_name.first 'last' => Form object, // root.person1_name.last 'first' => Form object, // root.person2_name.first 'last' => Form object, // root.person2_name.last ] ``` As you can see, The name `first` and `last` are used in two places, thus we cannot get result like that. (first/last of person1_name are overwritten by person2_name's) So the violation will finally lost the form where it should map to. It should pass `false` to `iterator_to_array`'s 2nd parameter. Commits ------- ae38660 [2.8] [Form] Modified iterator_to_array's 2nd parameter to false in ViolationMapper
Merged
This was referenced Jun 6, 2016
Merged
Merged
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This bug was introduced in PR #17099. So does not represent in 2.8.2 or older.
If we have the following structure form:
The following mapping for this form doesn't work correctly:
Cause
Because ViolationMapper uses
iterator_to_arrayin here to collect the sub forms.person1_nameandperson2_nameenableinherit_dataoption. So ViolationMapper will attempt to collect the sub forms of root form like this:[ 'first' => Form object, // root.person1_name.first 'last' => Form object, // root.person1_name.last 'first' => Form object, // root.person2_name.first 'last' => Form object, // root.person2_name.last ]As you can see, The name
firstandlastare used in two places, thus we cannot get result like that.(first/last of person1_name are overwritten by person2_name's)
So the violation will finally lost the form where it should map to. It should pass
falsetoiterator_to_array's 2nd parameter.