1
votes

following error message:

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__\XXX\YYYBundle\Entity\XXXGeo. You can avoid this error by setting the "data_class" option to "Proxies__CG__\XXX\YYYBundle\Entity\XXXGeo" or by adding a view transformer that transforms an instance of class Proxies__CG__\XXX\YYYBundle\Entity\XXXGeo to scalar, array or an instance of \ArrayAccess.

the field XXXGeo is an embedded form:

->add('geo',
            new XXXGeoType(),
            array(
                'required' => true
            )

here the code of it:

class XXXGeoType extends AbstractType
{
  public function buildForm(FormBuilderInterface $builder, array $options)
  {
    $builder
        ->add('address')
        ->add('city','text', array('data' => 'Somecity'))
        ->add('zip')
    ;
  }

  public function getDefaultOptions(array $options)
  {
    return array(
        'data_class' => 'XXX\YYYBundle\Entity\XXXGeo',
    );
  }

  public function getName()
  {
    return 'xxx_yyybundle_xxxgeotype';
  }
}
1
you know there are a lot of BC breaks in the forms between 2.1 and 2.3? Take a look at the UPGRADE-2.2 and UPGRADE-2.3 files in the root of the symfony package and update your code accordingly. Then, check if the problem still exists. - Wouter J

1 Answers

1
votes

You need to change getDefaultOptions method which is not used anymore for passing default options. Replace it with setDefaultOptions:

public function setDefaultOptions(OptionsResolverInterface $resolver)
{
    $resolver->setDefaults(array(
        'data_class' => 'XXX\YYYBundle\Entity\XXXGeo'
    ));
}