8000 [Form] expanded EntityType requires `data_class` option · Issue #15216 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Form] expanded EntityType requires data_class option #15216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rvanlaak opened this issue Jul 7, 2015 · 2 comments
Closed

[Form] expanded EntityType requires data_class option #15216

rvanlaak opened this issue Jul 7, 2015 · 2 comments

Comments

@rvanlaak
Copy link
Contributor
rvanlaak commented Jul 7, 2015

Since we've updated to 2.7.1 the EntityType with expanded: true does not accept an entity as a default value anymore. A LogicException occurs when the user goes back to edit the entity, where defaultData is added to the builder:

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

$defaultData = array();
if ($order->getSubject() instanceof Subject) {
    $defaultData['subject'] = $order->getSubject();
}

$form = $this->createFormBuilder($defaultData)
    ->add('subject', 'entity', array(
        'class'      => 'AppBundle:Order\Subject',
        'expanded'   => true,
        'property'   => 'name',
    ))
    ->getForm()
;

The exception can be solved in two ways, by setting expanded to false or by defining data_class:

// ...

$form = $this->createFormBuilder($defaultData)
    ->add('subject', 'entity', array(
        'class'      => 'AppBundle:Order\Subject',
        'data_class' => 'AppBundle\Entity\Order\Subject',
        'expanded'   => true,
        'property'   => 'name',
    ))
    ->getForm()
;

Looks like a BC break, think EntityType should resolve the data_class based on the class right?

@XWB
Copy link
Contributor
XWB commented Jul 7, 2015

You are not the only one experiencing this bug / BC break.

#14877

@rvanlaak
Copy link
Contributor Author
rvanlaak commented Jul 7, 2015

Thanks @XWB I'll close this one

@rvanlaak rvanlaak closed this as completed Jul 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0