From 477dac1e42725c272927a8c9b90ced164debfe79 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 30 Mar 2020 15:56:26 +0200 Subject: [PATCH 1/2] Remove the word "simple" --- form/form_collections.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/form/form_collections.rst b/form/form_collections.rst index 99c63bcfb83..cd1a7e2c240 100644 --- a/form/form_collections.rst +++ b/form/form_collections.rst @@ -19,7 +19,7 @@ that Task, right inside the same form. including the ``ManyToMany`` association mapping definition on the Task's ``tags`` property. -Let's start by creating a simple ``Task`` entity:: +Let's start by creating a ``Task`` entity:: // src/AppBundle/Entity/Task.php namespace AppBundle\Entity; From 2a0e7aba377170db943f335bea34df0515388ca1 Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Mon, 30 Mar 2020 13:55:21 +0200 Subject: [PATCH 2/2] Shortening the next paragraph --- form/form_collections.rst | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/form/form_collections.rst b/form/form_collections.rst index cd1a7e2c240..c40d4952e93 100644 --- a/form/form_collections.rst +++ b/form/form_collections.rst @@ -157,8 +157,7 @@ In your controller, you'll create a new form from the ``TaskType``:: { $task = new Task(); - // dummy code - this is here just so that the Task has some tags - // otherwise, this isn't an interesting example + // dummy code - add some tags to the task to play with $tag1 = new Tag(); $tag1->setName('tag1'); $task->getTags()->add($tag1); @@ -172,7 +171,7 @@ In your controller, you'll create a new form from the ``TaskType``:: $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - // ... maybe do some form processing, like saving the Task and Tag objects + // ... do your form processing, like saving the Task and Tag entities } return $this->render('task/new.html.twig', [ @@ -181,11 +180,8 @@ In your controller, you'll create a new form from the ``TaskType``:: } } -The corresponding template is now able to render both the ``description`` -field for the task form as well as all the ``TagType`` forms for any tags -that are already related to this ``Task``. In the above controller, I added -some dummy code so that you can see this in action (since a ``Task`` has -zero tags when first created). +In the template, we need to iterate over the existing ``TagType`` forms +to render them: .. code-block:: html+twig @@ -194,20 +190,15 @@ zero tags when first created). {# ... #} {{ form_start(form) }} - {# render the task's only field: description #} {{ form_row(form.description) }} -

Tags

{{ form_end(form) }} - {# ... #} - When the user submits the form, the submitted data for the ``tags`` field are used to construct an ``ArrayCollection`` of ``Tag`` objects, which is then set on the ``tag`` field of the ``Task`` instance.