{"action":"opened","issue":{"url":"https://api.github.com/repos/javiereguiluz/EasyAdminBundle/issues/109","labels_url":"https://api.github.com/repos/javiereguiluz/EasyAdminBundle/issues/109/labels{/name}","comments_url":"https://api.github.com/repos/javiereguiluz/EasyAdminBundle/issues/109/comments","events_url":"https://api.github.com/repos/javiereguiluz/EasyAdminBundle/issues/109/events","html_url":"https://github.com/javiereguiluz/EasyAdminBundle/issues/109","id":56238503,"number":109,"title":"Add embedded form support","user":{"login":"nlemahieu","id":5345463,"avatar_url":"https://avatars.githubusercontent.com/u/5345463?v=3","gravatar_id":"","url":"https://api.github.com/users/nlemahieu","html_url":"https://github.com/nlemahieu","followers_url":"https://api.github.com/users/nlemahieu/followers","following_url":"https://api.github.com/users/nlemahieu/following{/other_user}","gists_url":"https://api.github.com/users/nlemahieu/gists{/gist_id}","starred_url":"https://api.github.com/users/nlemahieu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nlemahieu/subscriptions","organizations_url":"https://api.github.com/users/nlemahieu/orgs","repos_url":"https://api.github.com/users/nlemahieu/repos","events_url":"https://api.github.com/users/nlemahieu/events{/privacy}","received_events_url":"https://api.github.com/users/nlemahieu/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-02-02T13:47:42Z","updated_at":"2015-02-02T13:47:42Z","closed_at":null,"body":"I would like to add the support of embedded form. Actually i've already add some code but i would like to have your opinion to know what solution is better.\r\n\r\nOn the principle, the feature need to be very simple, so to tell to the bundle that my field is an embedded form, i just put \"[]\" on my property, example:\r\n\r\n```\r\nSocialNetWork:\r\n            class: AppBundle\\Entity\\SocialNetwork\r\n            form:\r\n                fields: ['name', 'link', 'logo[]']\r\n```\r\n\r\n*Where logo is a relation OneToOne on the Media entity.*\r\n\r\nIn the configuration class i've add an entry in the array of each fields to tell if it is an embedded form or not. To do that, i've add some code in the filterEntityFieldsBasedOnConfiguration method:\r\n\r\n```\r\n...\r\n$embedForm = false;\r\n\r\nforeach ($configuredFields as $fieldName => $fieldConfiguration) {\r\n    if (strpos($fieldName, '[]') !== false) {\r\n        $fieldName = str_replace('[]', '', $fieldName);\r\n        $fieldConfiguration['property'] = str_replace('[]', '', $fieldConfiguration['property']);\r\n        $embedForm = true;\r\n    }\r\n    ...\r\n    $filteredFields[$fieldName]['embedForm'] = $embedForm;\r\n    ...\r\n}\r\n...\r\n```\r\n\r\nAnd to show fields of the embedded form in the admin, i've modified the AdminController to add a condition in the createEditForm method. To build the form, i use the fields which are define for the embedded entity. In my example, i have:\r\n\r\n```\r\nMedia:\r\n    class: AppBundle\\Entity\\Media\r\n    list:\r\n        fields: [{ property: 'overview', type: 'string' }, 'path', 'size', 'tag', 'createdAt']\r\n    form:\r\n        fields: [{ property: 'file', type: 'file' }]\r\nSocialNetWork:\r\n    class: AppBundle\\Entity\\SocialNetwork\r\n    form:\r\n        fields: ['name', 'link', 'logo[]']\r\n```\r\n\r\nSo in my network form, i would have a name, link, and file fields.\r\n\r\n```\r\n...\r\nif (true === $metadata['embedForm']) {\r\n    $entity = $this\r\n->get('easyadmin.configurator')\r\n->getEntityConfigurationByNamespace($metadata['targetEntity']);\r\n\r\n                if ($entity) {\r\n                    $formEmbed = $form->create($metadata['fieldName'], 'form');\r\n                    foreach($entity['edit']['fields'] as $embedName => $embedMetadata) {\r\n                        $formEmbed->add($embedName, $embedMetadata['type']);\r\n                    }\r\n                    $form->add($formEmbed);\r\n                }\r\n            } else {\r\n                $form->add($name, $metadata['type'], $formFieldOptions);\r\n            }\r\n...\r\n```\r\n\r\nActually, I don't think about all use cases but only in mine, so i need your help to finalize this feature to tell me if i forgot a case or if the method can be better."}}