A lot of tutorials are showing you how to create embedded forms with associations/relations -- what about unrelated entities?
I figured out you can pass the second entity as a parameter to the parent form, pass it normally to the embedded form via the 'data' parameter, which will let the embedded form update the object. Then just persist() the object back in the controller like normal. No crazy data/request wrangling necessary!
In the parent form: //... private $userConfig = null; public function __construct($userConfig = null) { $this->userConfig = $userConfig; } public function buildForm(FormBuilderInterface $builder, array $options) { //... $builder->add('userConfig', new UserConfigPartialType(), array( 'label' => false, 'required' => false, 'mapped' => false, 'data' => $this->userConfig )); //... }
In the controller: $form = $this->createForm(new Forms\UserType($userConfig), $user); $form->handleRequest($request); if($form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->persist($userConfig); $em->persist($user); $em->flush(); }
The UserConfigPartialType form is just a normal form with a couple form fields. Of course ideally you'd have a relationship between these entities, but this is nice if for some reason you can't (like Doctrine's bidirectionality being a pain in the butt.)