{"action":"created","issue":{"url":"https://api.github.com/repos/symfony/symfony/issues/18763","repository_url":"https://api.github.com/repos/symfony/symfony","labels_url":"https://api.github.com/repos/symfony/symfony/issues/18763/labels{/name}","comments_url":"https://api.github.com/repos/symfony/symfony/issues/18763/comments","events_url":"https://api.github.com/repos/symfony/symfony/issues/18763/events","html_url":"https://github.com/symfony/symfony/issues/18763","id":154477472,"number":18763,"title":"[Form][3.0] setData in FormEvents::SUBMIT doesn't work in compound forms","user":{"login":"tobske","id":13568578,"avatar_url":"https://avatars.githubusercontent.com/u/13568578?v=3","gravatar_id":"","url":"https://api.github.com/users/tobske","html_url":"https://github.com/tobske","followers_url":"https://api.github.com/users/tobske/followers","following_url":"https://api.github.com/users/tobske/following{/other_user}","gists_url":"https://api.github.com/users/tobske/gists{/gist_id}","starred_url":"https://api.github.com/users/tobske/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tobske/subscriptions","organizations_url":"https://api.github.com/users/tobske/orgs","repos_url":"https://api.github.com/users/tobske/repos","events_url":"https://api.github.com/users/tobske/events{/privacy}","received_events_url":"https://api.github.com/users/tobske/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/symfony/symfony/labels/Bug","name":"Bug","color":"e10c02"},{"url":"https://api.github.com/repos/symfony/symfony/labels/Form","name":"Form","color":"DDDDDD"},{"url":"https://api.github.com/repos/symfony/symfony/labels/Status:%20Needs%20Review","name":"Status: Needs Review","color":"ededed"},{"url":"https://api.github.com/repos/symfony/symfony/labels/Unconfirmed","name":"Unconfirmed","color":"444444"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-05-12T13:05:41Z","updated_at":"2016-05-25T12:57:10Z","closed_at":"2016-05-25T12:57:10Z","body":"If you have a compound form and you call `setData()` with changed data inside a listener for the `FormEvents::SUBMIT` the data is not changed correclty. When the `handleRequest()`  function is finished the normdata, viewdata and modeldata of the compound form are correct but the values of the children forms haven't changed. If you call `$form->createView()` after this the form doesn't contain the changes.\r\n\r\nExample code to reproduce bug:\r\nController:\r\n```PHP\r\npublic function newAction(Request $request)\r\n    {\r\n        $form = $this->createForm(FormName::class);\r\n        $form->handleRequest($request);\r\n        return $this->render(\r\n            \"AppBundle:Default:form.html.twig\",\r\n            [\r\n                'form' => $form->createView()\r\n            ]\r\n        );\r\n    }\r\n```\r\nForm:\r\n\r\n```PHP\r\nclass FeatureType extends AbstractType implements EventSubscriberInterface\r\n{\r\n    public function buildForm(FormBuilderInterface $builder, array $options)\r\n    {\r\n        $builder\r\n            ->add('name')\r\n            ->addEventSubscriber($this)\r\n        ;\r\n    }\r\n\r\n    public function configureOptions(OptionsResolver $resolver)\r\n    {\r\n        $resolver->setDefaults(['data_class' => 'Cat\\AppBundle\\PlainClasses\\Form\\FeatureDTO']);\r\n    }\r\n\r\n    public static function getSubscribedEvents()\r\n    {\r\n        return [\r\n            FormEvents::SUBMIT => 'submit'\r\n        ];\r\n    }\r\n\r\n    public function submit(FormEvent $event)\r\n    {\r\n        $data = $event->getData();\r\n        $data->name = 'test';\r\n        $event->setData($data);\r\n    }\r\n}\r\n```\r\nDTO:\r\n```PHP\r\nclass FeatureDTO\r\n{\r\n    /**\r\n     * @var string\r\n     */\r\n    public $name;\r\n}\r\n```\r\n\r\nWith this code you will see that the normdata, viewdata and modeldata of the complete form featureType is updated and the name is set to 'test' but the child form, the name form that is a TextType, still has an empty value so if you render the form the name field stays empty."},"comment":{"url":"https://api.github.com/repos/symfony/symfony/issues/comments/221567271","html_url":"https://github.com/symfony/symfony/issues/18763#issuecomment-221567271","issue_url":"https://api.github.com/repos/symfony/symfony/issues/18763","id":221567271,"user":{"login":"tobske","id":13568578,"avatar_url":"https://avatars.githubusercontent.com/u/13568578?v=3","gravatar_id":"","url":"https://api.github.com/users/tobske","html_url":"https://github.com/tobske","followers_url":"https://api.github.com/users/tobske/followers","following_url":"https://api.github.com/users/tobske/following{/other_user}","gists_url":"https://api.github.com/users/tobske/gists{/gist_id}","starred_url":"https://api.github.com/users/tobske/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tobske/subscriptions","organizations_url":"https://api.github.com/users/tobske/orgs","repos_url":"https://api.github.com/users/tobske/repos","events_url":"https://api.github.com/users/tobske/events{/privacy}","received_events_url":"https://api.github.com/users/tobske/received_events","type":"User","site_admin":false},"created_at":"2016-05-25T12:57:10Z","updated_at":"2016-05-25T12:57:10Z","body":"I already expected that the submit of the children has been handled before. I can't use the first option because I want to change a different field (e.g. 'age') that is on the same level as 'name'. So if I handle a event on name I can't change the data of another field then name, AFAIK. \r\nI will then have to go for the second options. Then I have to resolve some entities myself which would have been resolved automatically if I could use the SUBMIT event. \r\n\r\nIMHO it would be very helpful to add a extended workflow with child forms to the Form Events page in the cookbook (http://symfony.com/doc/current/components/form/form_events.html). This would help to undestand when which event on which form (parent or child) gets triggerd."}}
{"actor":{"display_login":"tobske"}}