Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Form] FormBuilder::add causes exception when given an object #18301

Closed
@twifty

Description

@twifty

I'm upgrading one of my bundles to the new version 3 standard and came across this bug.

Within my FormType, I add child types like so:

$builder->add('type', new SelectType(), array(
    'choices' => array_combine($choices, static::$defaultChoices),
    'required' => true,
    'data' => self::INCLUSIVE,
    'options' => array(
        'width' => 'auto',
    ),
));

The documentation for FormBuilder::add states that the second parameter $type accepts string|FormTypeInterface. But, stepping through the code, I see the child is added to the $unresolvedChildren array. Later when getForm is called, each of these children are resolved by passing that type to FormFactory::createNamedBuilder, which expects a string.

I don't know if this is a documentation error or in fact a bug in the code. I would prefer to pass in an instance of the child type since I can construct it accordingly. Using strings and services would be a pain.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions