Symfony Form – Expected argument of type "string or SymfonyComponentFormFormTypeInterface", "array" given

I have created a form with doctrine. It works if I do not pass any option, like this:

$builder
    ->add('name')
    ->add('password', 'password')
    ->add('password_repeat', 'password')
    ->add('email', 'email')
    ->add('save', 'submit')
;

But, if I add an array with options as it says the docs (http://symfony.com/doc/current/book/forms.html#book-form-creating-form-classes), I get an error that says:

Expected argument of type “string or SymfonyComponentFormFormTypeInterface”, “array” given

This is the formtype created by doctrine:

<?php

namespace MainBundleForm;

use SymfonyComponentFormAbstractType;
use SymfonyComponentFormFormBuilderInterface;
use SymfonyComponentOptionsResolverOptionsResolverInterface;

class UserType extends AbstractType
{
/**
 * @param FormBuilderInterface $builder
 * @param array $options
 */
public function buildForm(FormBuilderInterface $builder, array $options)
{

    $builder
        ->add('name') //if I put ->add('name', array('label' => 'Your name')) I get the error
        ->add('password', 'password')
        ->add('password_repeat', 'password')
        ->add('email', 'email')
        ->add('save', 'submit')
    ;

}

/**
 * @param OptionsResolverInterface $resolver
 */
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
    $resolver->setDefaults(array(
        'data_class' => 'MainBundleEntityUser'
    ));
}

/**
 * @return string
 */
public function getName()
{
    return 'mainbundle_user';
}
}


Source: forms

Leave a Reply