diff --git a/src/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationMapper.php b/src/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationMapper.php index 659c266ce6..2a024ee4b9 100644 --- a/src/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationMapper.php +++ b/src/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationMapper.php @@ -241,13 +241,6 @@ class ViolationMapper implements ViolationMapperInterface // Form inherits its parent data // Cut the piece out of the property path and proceed $propertyPathBuilder->remove($i); - } elseif (!$scope->getConfig()->getMapped()) { - // Form is not mapped - // Set the form as new origin and strip everything - // we have so far in the path - $origin = $scope; - $propertyPathBuilder->remove(0, $i + 1); - $i = 0; } else { /* @var \Symfony\Component\PropertyAccess\PropertyPathInterface $propertyPath */ $propertyPath = $scope->getPropertyPath(); diff --git a/src/Symfony/Component/Form/Tests/Extension/Validator/ViolationMapper/Fixtures/Issue.php b/src/Symfony/Component/Form/Tests/Extension/Validator/ViolationMapper/Fixtures/Issue.php new file mode 100644 index 0000000000..62b6a4e77d --- /dev/null +++ b/src/Symfony/Component/Form/Tests/Extension/Validator/ViolationMapper/Fixtures/Issue.php @@ -0,0 +1,16 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Form\Tests\Extension\Validator\ViolationMapper\Fixtures; + +class Issue +{ +} diff --git a/src/Symfony/Component/Form/Tests/Extension/Validator/ViolationMapper/ViolationMapperTest.php b/src/Symfony/Component/Form/Tests/Extension/Validator/ViolationMapper/ViolationMapperTest.php index 2fa3e92892..6e3fffc217 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Validator/ViolationMapper/ViolationMapperTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Validator/ViolationMapper/ViolationMapperTest.php @@ -22,6 +22,7 @@ use Symfony\Component\Form\Form; use Symfony\Component\Form\FormConfigBuilder; use Symfony\Component\Form\FormError; use Symfony\Component\Form\FormInterface; +use Symfony\Component\Form\Tests\Extension\Validator\ViolationMapper\Fixtures\Issue; use Symfony\Component\PropertyAccess\PropertyPath; use Symfony\Component\Validator\ConstraintViolation; use Symfony\Component\Validator\ConstraintViolationInterface; @@ -70,12 +71,12 @@ class ViolationMapperTest extends TestCase $this->params = ['foo' => 'bar']; } - protected function getForm($name = 'name', $propertyPath = null, $dataClass = null, $errorMapping = [], $inheritData = false, $synchronized = true) + protected function getForm($name = 'name', $propertyPath = null, $dataClass = null, $errorMapping = [], $inheritData = false, $synchronized = true, array $options = []) { $config = new FormConfigBuilder($name, $dataClass, $this->dispatcher, [ 'error_mapping' => $errorMapping, - ]); - $config->setMapped(true); + ] + $options); + $config->setMapped(isset($options['mapped']) ? $options['mapped'] : true); $config->setInheritData($inheritData); $config->setPropertyPath($propertyPath); $config->setCompound(true); @@ -96,9 +97,9 @@ class ViolationMapperTest extends TestCase * * @return ConstraintViolation */ - protected function getConstraintViolation($propertyPath) + protected function getConstraintViolation($propertyPath, $root = null) { - return new ConstraintViolation($this->message, $this->messageTemplate, $this->params, null, $propertyPath, null); + return new ConstraintViolation($this->message, $this->messageTemplate, $this->params, $root, $propertyPath, null); } /** @@ -112,6 +113,33 @@ class ViolationMapperTest extends TestCase return $error; } + public function testMappingErrorsWhenFormIsNotMapped() + { + $form = $this->getForm('name', null, Issue::class, [ + 'child1' => 'child2', + ]); + + $violation = $this->getConstraintViolation('children[child1].data', $form); + + $child1Form = $this->getForm('child1', null, null, [], false, true, [ + 'mapped' => false, + ]); + $child2Form = $this->getForm('child2', null, null, [], false, true, [ + 'mapped' => false, + ]); + + $form->add($child1Form); + $form->add($child2Form); + + $form->submit([]); + + $this->mapper->mapViolation($violation, $form); + + $this->assertCount(0, $form->getErrors()); + $this->assertCount(0, $form->get('child1')->getErrors()); + $this->assertCount(1, $form->get('child2')->getErrors()); + } + public function testMapToFormInheritingParentDataIfDataDoesNotMatch() { $violation = $this->getConstraintViolation('children[address].data.foo');