8000 merged branch bschussek/issue4427 (PR #4431) · beryllium/symfony@c61c740 · GitHub
[go: up one dir, main page]

Skip to content

Commit c61c740

Browse files
committed
merged branch bschussek/issue4427 (PR symfony#4431)
Commits ------- fc38e2b [Form] Fixed mapping of violations with empty paths to the root form Discussion ---------- [Form] Fixed mapping of violations with empty paths to the root form Bug fix: yes Feature addition: no Backwards compatibility break: no Symfony2 tests pass: yes Fixes the following tickets: - Todo: - --------------------------------------------------------------------------- by travisbot at 2012-05-27T12:57:36Z This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1447769) (merged fc38e2b into adf07f1).
2 parents 2c6818f + fc38e2b commit c61c740

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationMapper.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,22 @@ public function mapViolation(ConstraintViolation $violation, FormInterface $form
5252
{
5353
$this->allowNonSynchronized = $allowNonSynchronized;
5454

55-
$violationPath = new ViolationPath($violation->getPropertyPath());
56-
$relativePath = $this->reconstructPath($violationPath, $form);
55+
$violationPath = null;
56+
$relativePath = null;
5757
$match = false;
5858

59+
// Don't create a ViolationPath instance for empty property paths
60+
if (strlen($violation->getPropertyPath()) > 0) {
61+
$violationPath = new ViolationPath($violation->getPropertyPath());
62+
$relativePath = $this->reconstructPath($violationPath, $form);
63+
}
64+
65+
// This case happens if the violation path is empty and thus
66+
// the violation should be mapped to the root form
67+
if (null === $violationPath) {
68+
$this->scope = $form;
69+
}
70+
5971
// In general, mapping happens from the root form to the leaf forms
6072
// First, the rules of the root form are applied to determine
6173
// the subsequent descendant. The rules of this descendant are then
@@ -86,7 +98,7 @@ public function mapViolation(ConstraintViolation $violation, FormInterface $form
8698
// This case happens if an error happened in the data under a
8799
// virtual form that does not match any of the children of
88100
// the virtual form.
89-
if (!$match) {
101+
if (null !== $violationPath && !$match) {
90102
// If we could not map the error to anything more specific
91103
// than the root element, map it to the innermost directly
92104
// mapped form of the violation path

src/Symfony/Component/Form/Tests/Extension/Validator/ViolationMapper/ViolationMapperTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ public function provideDefaultTests()
221221

222222
return array(
223223
// mapping target, child name, its property path, grand child name, its property path, violation path
224+
array(self::LEVEL_0, 'address', 'address', 'street', 'street', ''),
225+
array(self::LEVEL_0, 'address', 'address', 'street', 'street', 'data'),
226+
224227
array(self::LEVEL_2, 'address', 'address', 'street', 'street', 'children[address].children[street].data'),
225228
array(self::LEVEL_2, 'address', 'address', 'street', 'street', 'children[address].children[street].data.prop'),
226229
array(self::LEVEL_2, 'address', 'address', 'street', 'street', 'children[address].data.street'),

0 commit comments

Comments
 (0)
0