Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Form][2.3/2.6] Problem with add child in buildForm() #14714

Copy link
Copy link
Closed
@flowmitry

Description

@flowmitry
Issue body actions

I think, I found bug in Form functional:

<?php
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;

class TestForm extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        // Ok
        $builder->add($builder->create('text_test', 'text'));

        // Error 
        $builder->add($builder->create('button_test', 'submit'));
    }

    public function getName()
    {
        return 'test_form';
    }
}

Error:

Expected argument of type "string, integer or Symfony\Component\Form\FormBuilder", "Symfony\Component\Form\SubmitButtonBuilder" given

It is because method \Symfony\Component\Form\FormBuilder::add() contains check for instanceof self and any button-like type inherited from ButtonBuilder.

Both builders (FormBuilder and ButtonBuilder) have interface \Symfony\Component\Form\FormBuilderInterface.
So, if we change check of $child in method FormBuilder::add() to instanceof \Symfony\Component\Form\FormBuilderInterface all will be fine.

I checked this situation on 2.3 and 2.6 versions. Both have a bug.

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.