Skip to content

Commit 7526793

Browse files
committed
Merge branch '4.4' into 5.4
* 4.4: Remove extra space in NotificationEmail Fix the usage of the Valid constraints in array-based forms [DI] fix `ServiceSubscriberTrait` bug where parent has `__call()` [HttpClient] Fix reading proxy settings from dotenv when curl is used [Process] Don't return executable directories in PhpExecutableFinder Center icons vertically in trace list
2 parents f5e3a0f + b256d44 commit 7526793

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

Extension/Validator/Constraints/FormValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function validate($form, Constraint $formConstraint)
113113
foreach ($constraints as $constraint) {
114114
// For the "Valid" constraint, validate the data in all groups
115115
if ($constraint instanceof Valid) {
116-
if (\is_object($data)) {
116+
if (\is_object($data) || \is_array($data)) {
117117
$validator->atPath('data')->validate($data, $constraint, $groups);
118118
}
119119

Tests/Extension/Validator/Constraints/FormValidatorFunctionalTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Form\AbstractType;
1616
use Symfony\Component\Form\CallbackTransformer;
1717
use Symfony\Component\Form\Exception\TransformationFailedException;
18+
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
1819
use Symfony\Component\Form\Extension\Core\Type\DateType;
1920
use Symfony\Component\Form\Extension\Core\Type\FormType;
2021
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
@@ -321,6 +322,35 @@ public function testCascadeValidationToChildFormsWithTwoValidConstraints2()
321322
$this->assertSame('children[author].data.email', $violations[1]->getPropertyPath());
322323
}
323324

325+
public function testCascadeValidationToArrayChildForm()
326+
{
327+
$form = $this->formFactory->create(FormType::class, null, [
328+
'data_class' => Review::class,
329+
])
330+
->add('title')
331+
->add('customers', CollectionType::class, [
332+
'mapped' => false,
333+
'entry_type' => CustomerType::class,
334+
'allow_add' => true,
335+
'constraints' => [new Valid()],
336+
]);
337+
338+
$form->submit([
339+
'title' => 'Sample Title',
340+
'customers' => [
341+
['email' => null],
342+
],
343+
]);
344+
345+
$violations = $this->validator->validate($form);
346+
347+
$this->assertCount(2, $violations);
348+
$this->assertSame('This value should not be blank.', $violations[0]->getMessage());
349+
$this->assertSame('data.rating', $violations[0]->getPropertyPath());
350+
$this->assertSame('This value should not be blank.', $violations[1]->getMessage());
351+
$this->assertSame('children[customers].data[0].email', $violations[1]->getPropertyPath());
352+
}
353+
324354
public function testCascadeValidationToChildFormsUsingPropertyPathsValidatedInSequence()
325355
{
326356
$form = $this->formFactory->create(FormType::class, null, [

0 commit comments

Comments
 (0)