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

Appearance settings

Commit df002d1

Browse filesBrowse files
committed
fix mapping errors from unmapped forms
1 parent 2e7b993 commit df002d1
Copy full SHA for df002d1

File tree

Expand file treeCollapse file tree

3 files changed

+49
-12
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+49
-12
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationMapper.php
-7Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,6 @@ private function reconstructPath(ViolationPath $violationPath, FormInterface $or
241241
// Form inherits its parent data
242242
// Cut the piece out of the property path and proceed
243243
$propertyPathBuilder->remove($i);
244-
} elseif (!$scope->getConfig()->getMapped()) {
245-
// Form is not mapped
246-
// Set the form as new origin and strip everything
247-
// we have so far in the path
248-
$origin = $scope;
249-
$propertyPathBuilder->remove(0, $i + 1);
250-
$i = 0;
251244
} else {
252245
/* @var \Symfony\Component\PropertyAccess\PropertyPathInterface $propertyPath */
253246
$propertyPath = $scope->getPropertyPath();
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Form\Tests\Extension\Validator\ViolationMapper\Fixtures;
13+
14+
class Issue
15+
{
16+
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Validator/ViolationMapper/ViolationMapperTest.php
+33-5Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Symfony\Component\Form\FormConfigBuilder;
2323
use Symfony\Component\Form\FormError;
2424
use Symfony\Component\Form\FormInterface;
25+
use Symfony\Component\Form\Tests\Extension\Validator\ViolationMapper\Fixtures\Issue;
2526
use Symfony\Component\PropertyAccess\PropertyPath;
2627
use Symfony\Component\Validator\ConstraintViolation;
2728
use Symfony\Component\Validator\ConstraintViolationInterface;
@@ -70,12 +71,12 @@ protected function setUp()
7071
$this->params = ['foo' => 'bar'];
7172
}
7273

73-
protected function getForm($name = 'name', $propertyPath = null, $dataClass = null, $errorMapping = [], $inheritData = false, $synchronized = true)
74+
protected function getForm($name = 'name', $propertyPath = null, $dataClass = null, $errorMapping = [], $inheritData = false, $synchronized = true, array $options = [])
7475
{
7576
$config = new FormConfigBuilder($name, $dataClass, $this->dispatcher, [
7677
'error_mapping' => $errorMapping,
77-
]);
78-
$config->setMapped(true);
78+
] + $options);
79+
$config->setMapped($options['mapped'] ?? true);
7980
$config->setInheritData($inheritData);
8081
$config->setPropertyPath($propertyPath);
8182
$config->setCompound(true);
@@ -96,9 +97,9 @@ function () { throw new TransformationFailedException(); }
9697
*
9798
* @return ConstraintViolation
9899
*/
99-
protected function getConstraintViolation($propertyPath)
100+
protected function getConstraintViolation($propertyPath, $root = null)
100101
{
101-
return new ConstraintViolation($this->message, $this->messageTemplate, $this->params, null, $propertyPath, null);
102+
return new ConstraintViolation($this->message, $this->messageTemplate, $this->params, $root, $propertyPath, null);
102103
}
103104

104105
/**
@@ -112,6 +113,33 @@ protected function getFormError(ConstraintViolationInterface $violation, FormInt
112113
return $error;
113114
}
114115

116+
public function testMappingErrorsWhenFormIsNotMapped()
117+
{
118+
$form = $this->getForm('name', null, Issue::class, [
119+
'child1' => 'child2',
120+
]);
121+
122+
$violation = $this->getConstraintViolation('children[child1].data', $form);
123+
124+
$child1Form = $this->getForm('child1', null, null, [], false, true, [
125+
'mapped' => false,
126+
]);
127+
$child2Form = $this->getForm('child2', null, null, [], false, true, [
128+
'mapped' => false,
129+
]);
130+
131+
$form->add($child1Form);
132+
$form->add($child2Form);
133+
134+
$form->submit([]);
135+
136+
$this->mapper->mapViolation($violation, $form);
137+
138+
$this->assertCount(0, $form->getErrors());
139+
$this->assertCount(0, $form->get('child1')->getErrors());
140+
$this->assertCount(1, $form->get('child2')->getErrors());
141+
}
142+
115143
public function testMapToFormInheritingParentDataIfDataDoesNotMatch()
116144
{
117145
$violation = $this->getConstraintViolation('children[address].data.foo');

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.