-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
[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 |
- Loading branch information
commit 75af6797b85263dc891bf6f41b08fc252942c566
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -147,12 +147,9 @@ public function mapViolation(ConstraintViolation $violation, FormInterface $form | |
*/ | ||
private function matchChild(FormInterface $form, PropertyPathIteratorInterface $it) | ||
{ | ||
// Remember at what property path underneath "data" | ||
// we are looking. Check if there is a child with that | ||
// path, otherwise increase path by one more piece | ||
$target = null; | ||
$chunk = ''; | ||
$foundChild = null; | ||
$foundAtIndex = 0; | ||
$foundAtIndex = null; | ||
|
||
// Construct mapping rules for the given form | ||
$rules = array(); | ||
|
@@ -164,17 +161,11 @@ private function matchChild(FormInterface $form, PropertyPathIteratorInterface $ | |
} | ||
} | ||
|
||
// Skip forms inheriting their parent data when iterating the children | ||
$childIterator = new \RecursiveIteratorIterator( | ||
$children = iterator_to_array(new \RecursiveIteratorIterator( | ||
new InheritDataAwareIterator($form) | ||
); | ||
|
||
// Make the path longer until we find a matching child | ||
while (true) { | ||
if (!$it->valid()) { | ||
return; | ||
} | ||
)); | ||
|
||
while ($it->valid()) { | ||
if ($it->isIndex()) { | ||
$chunk .= '['.$it->current().']'; | ||
} else { | ||
|
@@ -196,33 +187,27 @@ private function matchChild(FormInterface $form, PropertyPathIteratorInterface $ | |
} | ||
} | ||
|
||
// Test children unless we already found one | ||
if (null === $foundChild) { | ||
foreach ($childIterator as $child) { | ||
/* @var FormInterface $child */ | ||
$childPath = (string) $child->getPropertyPath(); | ||
|
||
// Child found, mark as return value | ||
if ($chunk === $childPath) { | ||
$foundChild = $child; | ||
$foundAtIndex = $it->key(); | ||
} | ||
/** @var FormInterface $child */ | ||
foreach ($children as $key => $child) { | ||
$childPath = (string) $child->getPropertyPath(); | ||
if ($childPath === $chunk) { | ||
$target = $child; | ||
$foundAtIndex = $it->key(); | ||
} elseif (strpos($childPath, $chunk) === 0) { | ||
continue; | ||
} | ||
|
||
unset($children[$key]); | ||
} | ||
|
||
// Add element to the chunk | ||
$it->next(); | ||
} | ||
|
||
// If we reached the end of the path or if there are no | ||
// more matching mapping rules, return the found child | ||
if (null !== $foundChild && (!$it->valid() || count($rules) === 0)) { | ||
// Reset index in case we tried to find mapping | ||
// rules further down the path | ||
$it->seek($foundAtIndex); | ||
|
||
return $foundChild; | ||
} | ||
if ($foundAtIndex !== null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yoda style |
||
$it->seek($foundAtIndex); | ||
} | ||
|
||
return $target; | ||
} | ||
|
||
/** | ||
|
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
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.
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.
we usually prefer yoda style (swapping left and right hands of comparisons)