merged branch bschussek/issue4686 (PR #4828)
Commits
-------
854daa8
[Form] Fixed errors not to be added onto non-synchronized forms
Discussion
----------
[Form] Fixed errors not to be added onto non-synchronized forms
Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: #4686
Todo: -
This commit is contained in:
commit
b260f30a2e
@ -66,14 +66,18 @@ class DelegatingValidator implements FormValidatorInterface
|
|||||||
foreach ($propertyPath->getElements() as $element) {
|
foreach ($propertyPath->getElements() as $element) {
|
||||||
$children = $child->getChildren();
|
$children = $child->getChildren();
|
||||||
if (!isset($children[$element])) {
|
if (!isset($children[$element])) {
|
||||||
$form->addError($error);
|
if ($form->isSynchronized()) {
|
||||||
|
$form->addError($error);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$child = $children[$element];
|
$child = $children[$element];
|
||||||
}
|
}
|
||||||
|
|
||||||
$child->addError($error);
|
if ($child->isSynchronized()) {
|
||||||
|
$child->addError($error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} elseif (count($violations = $this->validator->validate($form))) {
|
} elseif (count($violations = $this->validator->validate($form))) {
|
||||||
@ -85,12 +89,16 @@ class DelegatingValidator implements FormValidatorInterface
|
|||||||
|
|
||||||
foreach ($mapping as $mappedPath => $child) {
|
foreach ($mapping as $mappedPath => $child) {
|
||||||
if (preg_match($mappedPath, $propertyPath)) {
|
if (preg_match($mappedPath, $propertyPath)) {
|
||||||
$child->addError($error);
|
if ($child->isSynchronized()) {
|
||||||
|
$child->addError($error);
|
||||||
|
}
|
||||||
continue 2;
|
continue 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$form->addError($error);
|
if ($form->isSynchronized()) {
|
||||||
|
$form->addError($error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,9 +12,11 @@
|
|||||||
namespace Symfony\Tests\Component\Form\Extension\Validator\Validator;
|
namespace Symfony\Tests\Component\Form\Extension\Validator\Validator;
|
||||||
|
|
||||||
use Symfony\Component\Form\FormBuilder;
|
use Symfony\Component\Form\FormBuilder;
|
||||||
|
use Symfony\Component\Form\CallbackTransformer;
|
||||||
use Symfony\Component\Form\FormError;
|
use Symfony\Component\Form\FormError;
|
||||||
use Symfony\Component\Form\Util\PropertyPath;
|
use Symfony\Component\Form\Util\PropertyPath;
|
||||||
use Symfony\Component\Form\Extension\Validator\Validator\DelegatingValidator;
|
use Symfony\Component\Form\Extension\Validator\Validator\DelegatingValidator;
|
||||||
|
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||||
use Symfony\Component\Validator\ConstraintViolation;
|
use Symfony\Component\Validator\ConstraintViolation;
|
||||||
use Symfony\Component\Validator\ExecutionContext;
|
use Symfony\Component\Validator\ExecutionContext;
|
||||||
|
|
||||||
@ -85,6 +87,24 @@ class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
return $this->getBuilder($name, $propertyPath)->getForm();
|
return $this->getBuilder($name, $propertyPath)->getForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getNonSynchronizedForm()
|
||||||
|
{
|
||||||
|
$form = $this->getBuilder()
|
||||||
|
->appendClientTransformer(new CallbackTransformer(
|
||||||
|
function ($normValue) {
|
||||||
|
return $normValue;
|
||||||
|
},
|
||||||
|
function () {
|
||||||
|
throw new TransformationFailedException('Failed');
|
||||||
|
}
|
||||||
|
))
|
||||||
|
->getForm();
|
||||||
|
|
||||||
|
$form->bind('foobar');
|
||||||
|
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
|
||||||
protected function getMockForm()
|
protected function getMockForm()
|
||||||
{
|
{
|
||||||
return $this->getMock('Symfony\Tests\Component\Form\FormInterface');
|
return $this->getMock('Symfony\Tests\Component\Form\FormInterface');
|
||||||
@ -118,6 +138,21 @@ class DelegatingValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals(array($this->getFormError()), $form->getErrors());
|
$this->assertEquals(array($this->getFormError()), $form->getErrors());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testNoFormErrorsOnNonSynchronizedForm()
|
||||||
|
{
|
||||||
|
$form = $this->getNonSynchronizedForm();
|
||||||
|
|
||||||
|
$this->delegate->expects($this->once())
|
||||||
|
->method('validate')
|
||||||
|
->will($this->returnValue(array(
|
||||||
|
$this->getConstraintViolation('constrainedProp')
|
||||||
|
)));
|
||||||
|
|
||||||
|
$this->validator->validate($form);
|
||||||
|
|
||||||
|
$this->assertEquals(array(), $form->getErrors());
|
||||||
|
}
|
||||||
|
|
||||||
public function testFormErrorsOnChild()
|
public function testFormErrorsOnChild()
|
||||||
{
|
{
|
||||||
$parent = $this->getForm();
|
$parent = $this->getForm();
|
||||||
|
Reference in New Issue
Block a user