Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9aa6963

Browse files
committed
fixup
1 parent ac17db3 commit 9aa6963

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function validate($form, Constraint $formConstraint)
6666
if ($groups instanceof GroupSequence) {
6767
// Validate the data, the form AND nested fields in sequence
6868
$violationsCount = $this->context->getViolations()->count();
69-
$fieldPropertyPath = \is_object($data) ? 'data.%s' : '%s';
69+
$fieldPropertyPath = \is_object($data) ? 'children[%s]' : 'children%s';
7070
$hasChildren = $form->count() > 0;
7171
$this->resolvedGroups = $hasChildren ? new \SplObjectStorage() : null;
7272

@@ -85,7 +85,7 @@ public function validate($form, Constraint $formConstraint)
8585
// otherwise resolving the groups would reuse the same
8686
// sequence recursively, thus some fields could fail
8787
// in different steps without breaking early enough
88-
$this->resolvedGroups[$field] = [$group];
88+
$this->resolvedGroups[$field] = (array) $group;
8989
$validator->atPath(sprintf($fieldPropertyPath, $field->getPropertyPath()))->validate($field, $formConstraint);
9090
}
9191
}

src/Symfony/Component/Form/Tests/Extension/Validator/Type/FormTypeValidatorExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use Symfony\Component\Validator\Constraints\GroupSequence;
2222
use Symfony\Component\Validator\Constraints\Length;
2323
use Symfony\Component\Validator\Constraints\NotBlank;
24-
use Symfony\Component\Validator\Constraints\NotNull;
2524
use Symfony\Component\Validator\Constraints\Valid;
2625
use Symfony\Component\Validator\ConstraintViolationList;
2726
use Symfony\Component\Validator\Mapping\ClassMetadata;
@@ -131,6 +130,7 @@ public function testManyFieldsGroupSequenceWithConstraintsOption()
131130

132131
$this->assertCount(1, $errors);
133132
$this->assertInstanceOf(Length::class, $errors[0]->getCause()->getConstraint());
133+
$this->assertSame('children[lastName].data', $errors[0]->getCause()->getPropertyPath());
134134
}
135135

136136
protected function createForm(array $options = [])

src/Symfony/Component/Form/Tests/Extension/Validator/ValidatorExtensionTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,31 @@ public function testFieldsValidateInSequence()
113113
$this->assertInstanceOf(Length::class, $errors[0]->getCause()->getConstraint());
114114
}
115115

116+
public function testFieldsValidateInSequenceWithNestedGroupsArray()
117+
{
118+
$form = $this->createForm(FormType::class, null, [
119+
'validation_groups' => new GroupSequence([['group1', 'group2'], 'group3']),
120+
])
121+
->add('foo', TextType::class, [
122+
'constraints' => [new Length(['min' => 10, 'groups' => ['group1']])],
123+
])
124+
->add('bar', TextType::class, [
125+
'constraints' => [new Length(['min' => 10, 'groups' => ['group2']])],
126+
])
127+
->add('baz', TextType::class, [
128+
'constraints' => [new NotBlank(['groups' => ['group3']])],
129+
])
130+
;
131+
132+
$form->submit(['foo' => 'invalid', 'bar' => 'invalid', 'baz' => null]);
133+
134+
$errors = $form->getErrors(true);
135+
136+
$this->assertCount(2, $errors);
137+
$this->assertInstanceOf(Length::class, $errors[0]->getCause()->getConstraint());
138+
$this->assertInstanceOf(Length::class, $errors[1]->getCause()->getConstraint());
139+
}
140+
116141
private function createForm($type, $data = null, array $options = [])
117142
{
118143
$validator = Validation::createValidatorBuilder()

0 commit comments

Comments
 (0)