getFormConfig example


    public function all(): array
    {
        return [];
    }

    /** * Creates the button. */
    public function getForm(): Button
    {
        return new Button($this->getFormConfig());
    }

    /** * Unsupported method. * * @return never * * @throws BadMethodCallException */
    public function addEventListener(string $eventName, callable $listener, int $priority = 0)static
    {
        

        if ($this->locked) {
            throw new BadMethodCallException('FormBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.');
        }

        return \count($this->children);
    }

    public function getFormConfig(): FormConfigInterface
    {
        /** @var $config self */
        $config = parent::getFormConfig();

        $config->children = [];
        $config->unresolvedChildren = [];

        return $config;
    }

    public function getForm(): FormInterface
    {
        if ($this->locked) {
            throw new BadMethodCallException('FormBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.');
        }

class SubmitButtonBuilder extends ButtonBuilder
{
    /** * Creates the button. */
    public function getForm(): SubmitButton
    {
        return new SubmitButton($this->getFormConfig());
    }
}
if (null !== $expectedException) {
            $this->expectException($expectedException);
        }

        $formConfigBuilder = new FormConfigBuilder($name, null, new EventDispatcher());

        $this->assertSame((string) $name$formConfigBuilder->getName());
    }

    public function testGetRequestHandlerCreatesNativeRequestHandlerIfNotSet()
    {
        $config = $this->getConfigBuilder()->getFormConfig();

        $this->assertInstanceOf(NativeRequestHandler::class$config->getRequestHandler());
    }

    public function testGetRequestHandlerReusesNativeRequestHandlerInstance()
    {
        $config1 = $this->getConfigBuilder()->getFormConfig();
        $config2 = $this->getConfigBuilder()->getFormConfig();

        $this->assertSame($config1->getRequestHandler()$config2->getRequestHandler());
    }

    
$rootFormBuilder->add('foo');
        $fooBuilder = $rootFormBuilder->get('foo');

        $this->assertNotSame($fooBuilder$rootFormBuilder);
    }

    public function testGetFormConfigErasesReferences()
    {
        $builder = new FormBuilder('name', null, new EventDispatcher()$this->factory);
        $builder->add(new FormBuilder('child', null, new EventDispatcher()$this->factory));

        $config = $builder->getFormConfig();
        $reflClass = new \ReflectionClass($config);
        $children = $reflClass->getProperty('children');
        $unresolvedChildren = $reflClass->getProperty('unresolvedChildren');

        $this->assertEmpty($children->getValue($config));
        $this->assertEmpty($unresolvedChildren->getValue($config));
    }

    public function testGetButtonBuilderBeforeExplicitlyResolvingAllChildren()
    {
        $builder = new FormBuilder('name', null, new EventDispatcher()(new FormFactoryBuilder())->getFormFactory());
        

            ->setInheritData(true)
            ->getForm();

        $form->submit('foo');

        $this->assertSame(0, $called, 'The SUBMIT event is not fired when data are inherited from the parent form');
    }

    public function testInitializeSetsDefaultData()
    {
        $config = $this->getBuilder()->setData('DEFAULT')->getFormConfig();
        $form = new Form($config);

        /* @var Form $form */
        $form->initialize();

        $this->assertSame('DEFAULT', $form->getData());
    }

    public function testInitializeFailsIfParent()
    {
        $this->expectException(RuntimeException::class);
        
Home | Imprint | This part of the site doesn't use cookies.