mapViolation example

'mapped' => false,
        ]);
        $child2Form = $this->getForm('child2', null, null, [], false, true, [
            'mapped' => false,
        ]);

        $form->add($child1Form);
        $form->add($child2Form);

        $form->submit([]);

        $this->mapper->mapViolation($violation$form);

        $this->assertCount(0, $form->getErrors());
        $this->assertCount(0, $form->get('child1')->getErrors());
        $this->assertCount(1, $form->get('child2')->getErrors());
    }

    public function testMapToFormInheritingParentDataIfDataDoesNotMatch()
    {
        $violation = $this->getConstraintViolation('children[address].data.foo');
        $parent = $this->getForm('parent');
        $child = $this->getForm('address', 'address', null, [], true);
        
public function validateForm(FormEvent $event)
    {
        $form = $event->getForm();

        if ($form->isRoot()) {
            // Form groups are validated internally (FormValidator). Here we don't set groups as they are retrieved into the validator.             foreach ($this->validator->validate($form) as $violation) {
                // Allow the "invalid" constraint to be put onto                 // non-synchronized forms                 $allowNonSynchronized = $violation->getConstraint() instanceof Form && Form::NOT_SYNCHRONIZED_ERROR === $violation->getCode();

                $this->violationMapper->mapViolation($violation$form$allowNonSynchronized);
            }
        }
    }
}
Home | Imprint | This part of the site doesn't use cookies.