8000 fixup · symfony/symfony@faf06f1 · GitHub
[go: up one dir, main page]

Skip to content

Commit faf06f1

Browse files
committed
fixup
1 parent ac17db3 commit faf06f1

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ public function testManyFieldsGroupSequenceWithConstraintsOption()
131131

132132
$this->assertCount(1, $errors);
133133
$this->assertInstanceOf(Length::class, $errors[0]->getCause()->getConstraint());
134+
$this->assertSame('children[lastName].data', $errors[0]->getCause()->getPropertyPath());
134135
}
135136

136137
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)
0