diff --git a/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php b/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php index a706e5668622b..13b8e3d1248ad 100644 --- a/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php +++ b/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php @@ -43,9 +43,10 @@ public function validate($form, Constraint $constraint) if ($form->isSynchronized()) { // Validate the form data only if transformation succeeded $groups = self::getValidationGroups($form); + $data = $form->getData(); // Validate the data against its own constraints - if (self::allowDataWalking($form)) { + if ($form->isRoot() && (is_object($data) || is_array($data))) { foreach ($groups as $group) { $validator->atPath('data')->validate($form->getData(), null, $group); } @@ -114,38 +115,6 @@ public function validate($form, Constraint $constraint) } } - /** - * Returns whether the data of a form may be walked. - * - * @param FormInterface $form The form to test. - * - * @return bool Whether the graph walker may walk the data. - */ - private static function allowDataWalking(FormInterface $form) - { - $data = $form->getData(); - - // Scalar values cannot have mapped constraints - if (!is_object($data) && !is_array($data)) { - return false; - } - - // Root forms are always validated - if ($form->isRoot()) { - return true; - } - - // Non-root forms are validated if validation cascading - // is enabled in all ancestor forms - while (null !== ($form = $form->getParent())) { - if (!$form->getConfig()->getOption('cascade_validation')) { - return false; - } - } - - return true; - } - /** * Returns the validation groups of the given form. * diff --git a/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php b/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php index a6d0c9ffb1f1b..f328ba005759d 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php @@ -103,29 +103,7 @@ public function testValidateConstraints() $this->assertNoViolation(); } - public function testValidateIfParentWithCascadeValidation() - { - $object = $this->getMock('\stdClass'); - - $parent = $this->getBuilder('parent', null, array('cascade_validation' => true)) - ->setCompound(true) - ->setDataMapper($this->getDataMapper()) - ->getForm(); - $options = array('validation_groups' => array('group1', 'group2')); - $form = $this->getBuilder('name', '\stdClass', $options)->getForm(); - $parent->add($form); - - $form->setData($object); - - $this->expectValidateAt(0, 'data', $object, 'group1'); - $this->expectValidateAt(1, 'data', $object, 'group2'); - - $this->validator->validate($form, new Form()); - - $this->assertNoViolation(); - } - - public function testValidateIfChildWithValidConstraint() + public function testValidateChildIfValidConstraint() { $object = $this->getMock('\stdClass'); @@ -149,11 +127,11 @@ public function testValidateIfChildWithValidConstraint() $this->assertNoViolation(); } - public function testDontValidateIfParentWithoutCascadeValidation() + public function testDontValidateIfParentWithoutValidConstraint() { $object = $this->getMock('\stdClass'); - $parent = $this->getBuilder('parent', null, array('cascade_validation' => false)) + $parent = $this->getBuilder('parent', null) ->setCompound(true) ->setDataMapper($this->getDataMapper()) ->getForm(); @@ -183,13 +161,13 @@ public function testMissingConstraintIndex() $this->assertNoViolation(); } - public function testValidateConstraintsEvenIfNoCascadeValidation() + public function testValidateConstraintsOptionEvenIfNoValidConstraint() { $object = $this->getMock('\stdClass'); $constraint1 = new NotNull(array('groups' => array('group1', 'group2'))); $constraint2 = new NotBlank(array('groups' => 'group2')); - $parent = $this->getBuilder('parent', null, array('cascade_validation' => false)) + $parent = $this->getBuilder('parent', null) ->setCompound(true) ->setDataMapper($this->getDataMapper()) ->getForm(); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy