8000 [Form] Fixed mapping of violations with empty paths to the root form by webmozart · Pull Request #4431 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Form] Fixed mapping of violations with empty paths to the root form #4431

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

Merged
merged 1 commit into from
May 30, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,22 @@ public function mapViolation(ConstraintViolation $violation, FormInterface $form
{
$this->allowNonSynchronized = $allowNonSynchronized;

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

// Don't create a ViolationPath instance for empty property paths
if (strlen($violation->getPropertyPath()) > 0) {
$violationPath = new ViolationPath($violation->getPropertyPath());
$relativePath = $this->reconstructPath($violationPath, $form);
}

// This case happens if the violation path is empty and thus
// the violation should be mapped to the root form
if (null === $violationPath) {
$this->scope = $form;
}

// In general, mapping happens from the root form to the leaf forms
// First, the rules of the root form are applied to determine
// the subsequent descendant. The rules of this descendant are then
Expand Down Expand Up @@ -86,7 +98,7 @@ public function mapViolation(ConstraintViolation $violation, FormInterface $form
// This case happens if an error happened in the data under a
// virtual form that does not match any of the children of
// the virtual form.
if (!$match) {
if (null !== $violationPath && !$match) {
// If we could not map the error to anything more specific
// than the root element, map it to the innermost directly
// mapped form of the violation path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ public function provideDefaultTests()

return array(
// mapping target, child name, its property path, grand child name, its property path, violation path
array(self::LEVEL_0, 'address', 'address', 'street', 'street', ''),
array(self::LEVEL_0, 'address', 'address', 'street', 'street', 'data'),

array(self::LEVEL_2, 'address', 'address', 'street', 'street', 'children[address].children[street].data'),
array(self::LEVEL_2, 'address', 'address', 'street', 'street', 'children[address].children[street].data.prop'),
array(self::LEVEL_2, 'address', 'address', 'street', 'street', 'children[address].data.street'),
Expand Down
0