{"action":"closed","issue":{"url":"https://api.github.com/repos/symfony/symfony/issues/15216","labels_url":"https://api.github.com/repos/symfony/symfony/issues/15216/labels{/name}","comments_url":"https://api.github.com/repos/symfony/symfony/issues/15216/comments","events_url":"https://api.github.com/repos/symfony/symfony/issues/15216/events","html_url":"https://github.com/symfony/symfony/issues/15216","id":93483608,"number":15216,"title":"[Form] expanded EntityType requires `data_class` option","user":{"login":"Rvanlaak","id":2707563,"avatar_url":"https://avatars.githubusercontent.com/u/2707563?v=3","gravatar_id":"","url":"https://api.github.com/users/Rvanlaak","html_url":"https://github.com/Rvanlaak","followers_url":"https://api.github.com/users/Rvanlaak/followers","following_url":"https://api.github.com/users/Rvanlaak/following{/other_user}","gists_url":"https://api.github.com/users/Rvanlaak/gists{/gist_id}","starred_url":"https://api.github.com/users/Rvanlaak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Rvanlaak/subscriptions","organizations_url":"https://api.github.com/users/Rvanlaak/orgs","repos_url":"https://api.github.com/users/Rvanlaak/repos","events_url":"https://api.github.com/users/Rvanlaak/events{/privacy}","received_events_url":"https://api.github.com/users/Rvanlaak/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-07-07T09:29:23Z","updated_at":"2015-07-07T15:06:04Z","closed_at":"2015-07-07T15:06:04Z","body":"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:\r\n\r\n> 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.\r\n\r\n```php\r\n$defaultData = array();\r\nif ($order->getSubject() instanceof Subject) {\r\n\t$defaultData['subject'] = $order->getSubject();\r\n}\r\n    \t\r\n$form = $this->createFormBuilder($defaultData)\r\n    ->add('subject', 'entity', array(\r\n       \t'class' \t => 'AppBundle:Order\\Subject',\r\n        'expanded'\t => true,\r\n        'property'   => 'name',\r\n    ))\r\n    ->getForm()\r\n;\r\n```\r\n\r\nThe exception can be solved in two ways, by setting `expanded` to `false` or by defining `data_class`:\r\n\r\n```php\r\n\r\n// ...\r\n    \t\r\n$form = $this->createFormBuilder($defaultData)\r\n    ->add('subject', 'entity', array(\r\n       \t'class' \t => 'AppBundle:Order\\Subject',\r\n       \t'data_class' => 'AppBundle\\Entity\\Order\\Subject',\r\n        'expanded'\t => true,\r\n        'property'   => 'name',\r\n    ))\r\n    ->getForm()\r\n;\r\n```\r\nLooks like a BC break, think `EntityType` should resolve the `data_class` based on the `class` right?"}}