Skip to content

Form with radio buttons fails after Symfony 2.7 upgrade #14877

Closed
@XWB

Description

@XWB

Imagine this form:

public function buildForm(FormBuilderInterface $builder, array $options)
{
        $builder->add('transportType', 'entity',
            array(
                'class' => 'MyBundle:TransportType',
                'property' => 'language.name',
                'expanded' => true,
                'query_builder' => function (EntityRepository $er) {
                    return $er->createQueryBuilder('e')
                        ->join('e.language', 'l')
                        ->orderBy('l.name', 'DESC');
                },
            )
        );
}

public function setDefaultOptions(OptionsResolverInterface $resolver)
{
        $resolver->setDefaults(array(
            'data_class' => 'BLA\MyBundle\Form\Model\Shipping',
        ));
}

After upgrading to Symfony 2.7, the form throws the following exception:

An exception has been thrown during the rendering of a template ("The form's view data is expected to be of type scalar, array or an instance of \ArrayAccess, but is an instance of class Proxies\__CG__\BLA\MyBundle\Entity\TransportType. You can avoid this error by setting the "data_class" option to "Proxies\__CG__\BLA\MyBundle\Entity\TransportType" or by adding a view transformer that transforms an instance of class Proxies\__CG__\BLA\MyBundle\Entity\TransportType to scalar, array or an instance of \ArrayAccess.") in MyBundle:Shipping:form.html.twig at line 8.

Setting the data_class seems to work but I wonder why this has not been documented in the upgrade file?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions