Skip to content

[2.3][Form][Collection] - Regression causing an UnexpectedTypeException #8527

Closed
@jkelley05

Description

@jkelley05

In my web application I commonly use the pattern of mapping a collection of fields to an array on one of my entities. As of upgrading to 2.3 today I've noticed that if a collection has only one field and that is empty, then an UnexpectedTypeException is thrown on line 76 of EventListener/ResizeFormListener.php. I tried adding an empty_data option of either null or array to both the collections and the field, but an empty string was still returned.

Also, the data is being posted as an array application[person][citizenship][countries][0], which class would be squishing this down to a string?

This is an example of one of my collections, here the aaws field is just a choice that gets its values from a webservice.

$builder->add('countries', 'collection', array('type' => 'aaws', 'options' => array(
                                                                 'label' => 'Citizenship Country', 
                                                                 'app_data_attr' => 'countries', 
                                                                 'empty_value' => 'Choose an option',
                                                                 'empty_data'  => null,
                                                                 'required' => false,
                                                                 'preferred_choices' => array('USA'),
                                                                 'attr' => array('class' => 'gfu-required-field')
                                                                  ),
                                                                 'allow_add' => true,
                                                                 'allow_delete' => true,
                                                                 'prototype' => true,
                                                                 'error_bubbling' => false,
                                                                 'empty_data' => null,
                                                  )

Here is the plain text of my stack trace

[1] Symfony\Component\Form\Exception\UnexpectedTypeException: Expected argument of type "array or (\Traversable and \ArrayAccess)", "string" given
    at n/a
        in /vagrant/vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Core/EventListener/ResizeFormListener.php line 76

    at Symfony\Component\Form\Extension\Core\EventListener\ResizeFormListener->preSetData(object(FormEvent))
        in  line 

    at call_user_func(array(object(ResizeFormListener), 'preSetData'), object(FormEvent))
        in /vagrant/app/cache/dev/classes.php line 1676

    at Symfony\Component\EventDispatcher\EventDispatcher->doDispatch(array(array(object(ResizeFormListener), 'preSetData')), 'form.pre_set_data', object(FormEvent))
        in /vagrant/app/cache/dev/classes.php line 1609

    at Symfony\Component\EventDispatcher\EventDispatcher->dispatch('form.pre_set_data', object(FormEvent))
        in /vagrant/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/ImmutableEventDispatcher.php line 42

    at Symfony\Component\EventDispatcher\ImmutableEventDispatcher->dispatch('form.pre_set_data', object(FormEvent))
        in /vagrant/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 321

    at Symfony\Component\Form\Form->setData('')
        in /vagrant/vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Core/DataMapper/PropertyPathMapper.php line 59

    at Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper->mapDataToForms(object(Ethnicity), object(RecursiveIteratorIterator))
        in /vagrant/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 375

    at Symfony\Component\Form\Form->setData(object(Ethnicity))
        in /vagrant/vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Core/DataMapper/PropertyPathMapper.php line 59

    at Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper->mapDataToForms(object(Person), object(RecursiveIteratorIterator))
        in /vagrant/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 375

    at Symfony\Component\Form\Form->setData(object(Person))
        in /vagrant/vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Core/DataMapper/PropertyPathMapper.php line 59

    at Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper->mapDataToForms(object(Application), object(RecursiveIteratorIterator))
        in /vagrant/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 375

    at Symfony\Component\Form\Form->setData(object(Application))
        in /vagrant/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 467

    at Symfony\Component\Form\Form->initialize()
        in /vagrant/vendor/symfony/symfony/src/Symfony/Component/Form/FormBuilder.php line 229

    at Symfony\Component\Form\FormBuilder->getForm()
        in /vagrant/vendor/symfony/symfony/src/Symfony/Component/Form/FormFactory.php line 39

    at Symfony\Component\Form\FormFactory->create(object(ApplicationType), object(Application), array('validation_groups' => array('Default'), 'gfu_submit' => false))
        in /vagrant/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php line 163

    at Symfony\Bundle\FrameworkBundle\Controller\Controller->createForm(object(ApplicationType), object(Application), array('validation_groups' => array('Default'), 'gfu_submit' => false))
        in /vagrant/src/Gfu/AppBundle/Controller/AppController.php line 472

    at Gfu\AppBundle\Controller\AppController->editAction('72', object(Request))
        in  line 

    at call_user_func_array(array(object(AppController), 'editAction'), array('72', object(Request)))
        in /vagrant/app/bootstrap.php.cache line 2774

    at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1')
        in /vagrant/app/bootstrap.php.cache line 2748

    at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true)
        in /vagrant/app/bootstrap.php.cache line 2878

    at Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(object(Request), '1', true)
        in /vagrant/app/bootstrap.php.cache line 2179

    at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
        in /vagrant/web/app_dev.php line 28

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