Skip to content

Commit f0bce9e

Browse files
committed
Merge branch '3.4' into 4.4
* 3.4: Shortening the next paragraph Removing redundant info
2 parents f8119c1 + 18bfe44 commit f0bce9e

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

form/form_collections.rst

+6-13
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ that Task, right inside the same form.
1919
including the ``ManyToMany`` association mapping definition on the Task's
2020
``tags`` property.
2121

22-
First, suppose that each ``Task`` belongs to multiple ``Tag`` objects. Start
23-
by creating a simple ``Task`` class::
22+
Let's start by creating a ``Task`` entity::
2423

2524
// src/Entity/Task.php
2625
namespace App\Entity;
@@ -30,7 +29,6 @@ by creating a simple ``Task`` class::
3029
class Task
3130
{
3231
protected $description;
33-
3432
protected $tags;
3533

3634
public function __construct()
@@ -159,8 +157,8 @@ In your controller, you'll create a new form from the ``TaskType``::
159157
{
160158
$task = new Task();
161159

162-
// dummy code - this is here just so that the Task has some tags
163-
// otherwise, this isn't an interesting example
160+
// dummy code - add some example tags to the task
161+
// (otherwise, the template will render an empty list of tags)
164162
$tag1 = new Tag();
165163
$tag1->setName('tag1');
166164
$task->getTags()->add($tag1);
@@ -174,7 +172,7 @@ In your controller, you'll create a new form from the ``TaskType``::
174172
$form->handleRequest($request);
175173

176174
if ($form->isSubmitted() && $form->isValid()) {
177-
// ... maybe do some form processing, like saving the Task and Tag objects
175+
// ... do your form processing, like saving the Task and Tag entities
178176
}
179177

180178
return $this->render('task/new.html.twig', [
@@ -183,11 +181,8 @@ In your controller, you'll create a new form from the ``TaskType``::
183181
}
184182
}
185183

186-
The corresponding template is now able to render both the ``description``
187-
field for the task form as well as all the ``TagType`` forms for any tags
188-
that are already related to this ``Task``. In the above controller, I added
189-
some dummy code so that you can see this in action (since a ``Task`` has
190-
zero tags when first created).
184+
In the template, you can now iterate over the existing ``TagType`` forms
185+
to render them:
191186

192187
.. code-block:: html+twig
193188

@@ -196,12 +191,10 @@ zero tags when first created).
196191
{# ... #}
197192

198193
{{ form_start(form) }}
199-
{# render the task's only field: description #}
200194
{{ form_row(form.description) }}
201195

202196
<h3>Tags</h3>
203197
<ul class="tags">
204-
{# iterate over each existing tag and render its only field: name #}
205198
{% for tag in form.tags %}
206199
<li>{{ form_row(tag.name) }}</li>
207200
{% endfor %}

0 commit comments

Comments
 (0)