{"action":"created","issue":{"url":"https://api.github.com/repos/symfony/symfony/issues/16476","repository_url":"https://api.github.com/repos/symfony/symfony","labels_url":"https://api.github.com/repos/symfony/symfony/issues/16476/labels{/name}","comments_url":"https://api.github.com/repos/symfony/symfony/issues/16476/comments","events_url":"https://api.github.com/repos/symfony/symfony/issues/16476/events","html_url":"https://github.com/symfony/symfony/issues/16476","id":115352500,"number":16476,"title":"Data transformer didn't work on entity field type","user":{"login":"bilougit","id":1367298,"avatar_url":"https://avatars.githubusercontent.com/u/1367298?v=3","gravatar_id":"","url":"https://api.github.com/users/bilougit","html_url":"https://github.com/bilougit","followers_url":"https://api.github.com/users/bilougit/followers","following_url":"https://api.github.com/users/bilougit/following{/other_user}","gists_url":"https://api.github.com/users/bilougit/gists{/gist_id}","starred_url":"https://api.github.com/users/bilougit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bilougit/subscriptions","organizations_url":"https://api.github.com/users/bilougit/orgs","repos_url":"https://api.github.com/users/bilougit/repos","events_url":"https://api.github.com/users/bilougit/events{/privacy}","received_events_url":"https://api.github.com/users/bilougit/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2015-11-05T19:13:21Z","updated_at":"2016-05-11T09:27:57Z","closed_at":"2015-11-06T11:12:08Z","body":"I couldn't make the \"harder example\" of the data transformer page work on an entity field type http://symfony.com/doc/current/cookbook/form/data_transformers.html#harder-example-transforming-an-issue-number-into-an-issue-entity.\r\n\r\nCreated a class which implements DataTransformerInterface, which is called this way\r\n\r\n```php\r\n// My form\r\n$builder\r\n            ->add('state', 'entity', array(\r\n                'placeholder'     => 'Choose a country',\r\n                'class'           => 'espace\\de\\nom\\State',\r\n                'attr'            => $array,\r\n                'choices'         => $options['states'],\r\n                'invalid_message' => 'That is not a valid state key ',\r\n            ));\r\n\r\n$builder->get('state')->addModelTransformer(\r\n    new MyTransformer($this->em)\r\n);\r\n\r\n// My transformer\r\nclass MyTransformer  implements DataTransformerInterface\r\n{\r\n     // Output of this is NULL\r\n     public function transform($entity) {\r\n          var_dump($entity); die('');\r\n          .....\r\n     }\r\n\r\n    // This is never called, (obviously I took care of removing the debug stuff into transform\r\n    // method first\r\n    public function reverseTransform($string) {\r\n          var_dump($string); die('');\r\n    }\r\n```\r\n\r\nWhen I remove all die and var_dump, getErrors(true) on my form after handleRequest shows up:\r\n\r\n```\r\nThis is not a valid state key\r\n```\r\n\r\nAnd the deeper one\r\n```\r\nUnable to reverse value for property path \"state\": The choice \"LA\" does not exist or is not unique\r\n```"},"comment":{"url":"https://api.github.com/repos/symfony/symfony/issues/comments/218407968","html_url":"https://github.com/symfony/symfony/issues/16476#issuecomment-218407968","issue_url":"https://api.github.com/repos/symfony/symfony/issues/16476","id":218407968,"user":{"login":"steady-daddy","id":2090011,"avatar_url":"https://avatars.githubusercontent.com/u/2090011?v=3","gravatar_id":"","url":"https://api.github.com/users/steady-daddy","html_url":"https://github.com/steady-daddy","followers_url":"https://api.github.com/users/steady-daddy/followers","following_url":"https://api.github.com/users/steady-daddy/following{/other_user}","gists_url":"https://api.github.com/users/steady-daddy/gists{/gist_id}","starred_url":"https://api.github.com/users/steady-daddy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/steady-daddy/subscriptions","organizations_url":"https://api.github.com/users/steady-daddy/orgs","repos_url":"https://api.github.com/users/steady-daddy/repos","events_url":"https://api.github.com/users/steady-daddy/events{/privacy}","received_events_url":"https://api.github.com/users/steady-daddy/received_events","type":"User","site_admin":false},"created_at":"2016-05-11T09:27:57Z","updated_at":"2016-05-11T09:27:57Z","body":"Complex stuff that. Thanks anyways, will try later and let you know if that works."}}