[Form] fixed validation when using the 'validation_constraint' option
This commit is contained in:
parent
5182a0c2c4
commit
af67e65cbd
@ -18,6 +18,7 @@ use Symfony\Component\Form\Util\VirtualFormAwareIterator;
|
|||||||
use Symfony\Component\Form\Exception\FormException;
|
use Symfony\Component\Form\Exception\FormException;
|
||||||
use Symfony\Component\Validator\ValidatorInterface;
|
use Symfony\Component\Validator\ValidatorInterface;
|
||||||
use Symfony\Component\Validator\ExecutionContext;
|
use Symfony\Component\Validator\ExecutionContext;
|
||||||
|
use Symfony\Component\Form\Util\PropertyPath;
|
||||||
|
|
||||||
class DelegatingValidator implements FormValidatorInterface
|
class DelegatingValidator implements FormValidatorInterface
|
||||||
{
|
{
|
||||||
@ -53,11 +54,29 @@ class DelegatingValidator implements FormValidatorInterface
|
|||||||
$form->getAttribute('validation_constraint'),
|
$form->getAttribute('validation_constraint'),
|
||||||
self::getFormValidationGroups($form)
|
self::getFormValidationGroups($form)
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
$violations = $this->validator->validate($form);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($violations) {
|
if ($violations) {
|
||||||
|
foreach ($violations as $violation) {
|
||||||
|
$propertyPath = new PropertyPath($violation->getPropertyPath());
|
||||||
|
$template = $violation->getMessageTemplate();
|
||||||
|
$parameters = $violation->getMessageParameters();
|
||||||
|
$error = new FormError($template, $parameters);
|
||||||
|
|
||||||
|
$child = $form;
|
||||||
|
foreach ($propertyPath->getElements() as $element) {
|
||||||
|
$children = $child->getChildren();
|
||||||
|
if (!isset($children[$element])) {
|
||||||
|
$form->addError($error);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$child = $children[$element];
|
||||||
|
}
|
||||||
|
|
||||||
|
$child->addError($error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} elseif ($violations = $this->validator->validate($form)) {
|
||||||
foreach ($violations as $violation) {
|
foreach ($violations as $violation) {
|
||||||
$propertyPath = $violation->getPropertyPath();
|
$propertyPath = $violation->getPropertyPath();
|
||||||
$template = $violation->getMessageTemplate();
|
$template = $violation->getMessageTemplate();
|
||||||
|
Reference in New Issue
Block a user