createBuilderForProperty example


        return $this->createBuilder($type$data$options)->getForm();
    }

    public function createNamed(string $name, string $type = FormType::class, mixed $data = null, array $options = []): FormInterface
    {
        return $this->createNamedBuilder($name$type$data$options)->getForm();
    }

    public function createForProperty(string $class, string $property, mixed $data = null, array $options = []): FormInterface
    {
        return $this->createBuilderForProperty($class$property$data$options)->getForm();
    }

    public function createBuilder(string $type = FormType::class, mixed $data = null, array $options = []): FormBuilderInterface
    {
        return $this->createNamedBuilder($this->registry->getType($type)->getBlockPrefix()$type$data$options);
    }

    public function createNamedBuilder(string $name, string $type = FormType::class, mixed $data = null, array $options = []): FormBuilderInterface
    {
        if (null !== $data && !\array_key_exists('data', $options)) {
            $options['data'] = $data;
        }
public function testCreateNamed()
    {
        $form = $this->factory->createNamed('name', ConfigurableFormType::class, null, ['a' => '1', 'b' => '2']);

        $this->assertSame('1', $form->getConfig()->getOption('a'));
        $this->assertSame('2', $form->getConfig()->getOption('b'));
    }

    public function testCreateBuilderForPropertyWithoutTypeGuesser()
    {
        $builder = $this->factory->createBuilderForProperty('Application\Author', 'firstName');

        $this->assertSame('firstName', $builder->getName());
    }

    public function testCreateBuilderForPropertyCreatesFormWithHighestConfidence()
    {
        $this->guesser1->configureTypeGuess(TextType::class['attr' => ['maxlength' => 10]], Guess::MEDIUM_CONFIDENCE);
        $this->guesser2->configureTypeGuess(PasswordType::class['attr' => ['maxlength' => 7]], Guess::HIGH_CONFIDENCE);

        $builder = $this->factory->createBuilderForProperty('Application\Author', 'firstName');

        
throw new BadMethodCallException('FormBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.');
        }

        if (null === $type && null === $this->getDataClass()) {
            $type = TextType::class;
        }

        if (null !== $type) {
            return $this->getFormFactory()->createNamedBuilder($name$type, null, $options);
        }

        return $this->getFormFactory()->createBuilderForProperty($this->getDataClass()$name, null, $options);
    }

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

        if (isset($this->unresolvedChildren[$name])) {
            return $this->resolveChild($name);
        }

        
Home | Imprint | This part of the site doesn't use cookies.