getValidationGroups example

if (!$form instanceof FormInterface) {
            return;
        }

        /* @var FormInterface $form */
        $config = $form->getConfig();

        $validator = $this->context->getValidator()->inContext($this->context);

        if ($form->isSubmitted() && $form->isSynchronized()) {
            // Validate the form data only if transformation succeeded             $groups = $this->getValidationGroups($form);

            if (!$groups) {
                return;
            }

            $data = $form->getData();
            // Validate the data against its own constraints             $validateDataGraph = $form->isRoot()
                && (\is_object($data) || \is_array($data))
                && (($groups && \is_array($groups)) || ($groups instanceof GroupSequence && $groups->groups))
            ;

            
$this->expectValidateAt(0, 'data', $object, 'group1');
        $this->expectValidateAt(1, 'data', $object, 'group2');

        $this->validator->validate($formnew Form());

        $this->assertNoViolation();
    }

    public function testHandleCallbackValidationGroups()
    {
        $object = new \stdClass();
        $options = ['validation_groups' => $this->getValidationGroups(...)];
        $form = $this->getCompoundForm($object$options);
        $form->submit([]);

        $this->expectValidateAt(0, 'data', $object['group1', 'group2']);

        $this->validator->validate($formnew Form());

        $this->assertNoViolation();
    }

    public function testDontExecuteFunctionNames()
    {
Home | Imprint | This part of the site doesn't use cookies.