diff --git a/form/form_collections.rst b/form/form_collections.rst index 99c63bcfb83..c40d4952e93 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; @@ -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) }} -