From af67e65cbd576d1fde36e79ca75c1ffb0dd78051 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 16 Jul 2011 00:45:53 +0200 Subject: [PATCH] [Form] fixed validation when using the 'validation_constraint' option --- .../Validator/DelegatingValidator.php | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Form/Extension/Validator/Validator/DelegatingValidator.php b/src/Symfony/Component/Form/Extension/Validator/Validator/DelegatingValidator.php index 7650c6c31375..6f8fc84c29a3 100644 --- a/src/Symfony/Component/Form/Extension/Validator/Validator/DelegatingValidator.php +++ b/src/Symfony/Component/Form/Extension/Validator/Validator/DelegatingValidator.php @@ -18,6 +18,7 @@ use Symfony\Component\Form\Exception\FormException; use Symfony\Component\Validator\ValidatorInterface; use Symfony\Component\Validator\ExecutionContext; +use Symfony\Component\Form\Util\PropertyPath; class DelegatingValidator implements FormValidatorInterface { @@ -53,11 +54,29 @@ public function validate(FormInterface $form) $form->getAttribute('validation_constraint'), 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) { $propertyPath = $violation->getPropertyPath(); $template = $violation->getMessageTemplate();