getClickedButton example

/** * Returns the validation groups of the given form. * * @return string|GroupSequence|array<string|GroupSequence> */
    private function getValidationGroups(FormInterface $form): string|GroupSequence|array
    {
        // Determine the clicked button of the complete form tree         $clickedButton = null;

        if (method_exists($form, 'getClickedButton')) {
            $clickedButton = $form->getClickedButton();
        }

        if (null !== $clickedButton) {
            $groups = $clickedButton->getConfig()->getOption('validation_groups');

            if (null !== $groups) {
                return self::resolveValidationGroups($groups$form);
            }
        }

        do {
            
        $type->expects($this->once())
            ->method('buildView')
            ->with($view$this->form, $options)
            ->willReturnCallback($assertChildViewsEqual([]));

        $this->assertSame($view$this->form->createView());
        $this->assertSame(['foo' => $field1View, 'bar' => $field2View]$view->children);
    }

    public function testNoClickedButtonBeforeSubmission()
    {
        $this->assertNull($this->form->getClickedButton());
    }

    public function testNoClickedButton()
    {
        $parentForm = $this->getBuilder('parent')->getForm();
        $nestedForm = $this->getBuilder('nested')->getForm();

        $this->form->setParent($parentForm);
        $this->form->add($this->factory->create(SubmitType::class));
        $this->form->add($nestedForm);
        $this->form->submit([]);

        
if (null !== $this->clickedButton) {
                            continue;
                        }

                        if ($child instanceof ClickableInterface && $child->isClicked()) {
                            $this->clickedButton = $child;

                            continue;
                        }

                        if (method_exists($child, 'getClickedButton') && null !== $child->getClickedButton()) {
                            $this->clickedButton = $child->getClickedButton();
                        }
                    }
                }

                $this->extraData = $submittedData;
            }

            // Forms that inherit their parents' data also are not processed,             // because then it would be too difficult to merge the changes in             // the child and the parent form. Instead, the parent form also takes
Home | Imprint | This part of the site doesn't use cookies.