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] Fixed violation mapping if multiple forms are using the same (or part of the same) property path#17099

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

Closed
alekitto wants to merge2 commits intosymfony:2.3fromalekitto:ticket_5656

Conversation

@alekitto
Copy link
Contributor

QA
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#5656
LicenseMIT
Doc PR

@nicolas-grekasnicolas-grekas changed the title[Form] Fixed violation mapping if multiple forms are using the same (…[Form] Fixed violation mapping if multiple forms are using the same (or part of the same) property pathDec 22, 2015

Choose a reason for hiding this comment

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

we usually prefer yoda style (swapping left and right hands of comparisons)

…or part of the same) property path| Q             | A| ------------- | ---| Bug fix?      | yes| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |symfony#5656| License       | MIT| Doc PR        |
@alekitto
Copy link
ContributorAuthor

@nicolas-grekas: ok, comparisons edited as you suggested

@fabpot
Copy link
Member

Thank you@alekitto.

fabpot added a commit that referenced this pull requestFeb 15, 2016
… the same (or part of the same) property path (alekitto)This PR was squashed before being merged into the 2.3 branch (closes#17099).Discussion----------[Form] Fixed violation mapping if multiple forms are using the same (or part of the same) property path| Q             | A| ------------- | ---| Bug fix?      | yes| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#5656| License       | MIT| Doc PR        |Commits-------f005c80 [Form] Fixed violation mapping if multiple forms are using the same (or part of the same) property path
@fabpotfabpot closed thisFeb 15, 2016
fabpot added a commit that referenced this pull requestFeb 17, 2016
This PR was merged into the 2.7 branch.Discussion----------[Form] fix violation mapper tests| Q             | A| ------------- | ---| Bug fix?      | yes| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#17099| License       | MIT| Doc PR        |This takes into account the changes to the `getErrors()` in Symfony 2.5(the method rturns a `FormErrorIterator` instead of an array) as well asthe fact that non-submitted forms do not accept errors since#10567anymore.Commits-------f87558d [Form] fix violation mapper tests
This was referencedFeb 28, 2016
fabpot added a commit that referenced this pull requestMay 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/aThis 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.```## CauseBecause 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
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@alekitto@fabpot@nicolas-grekas

[8]ページ先頭

©2009-2025 Movatter.jp