Skip to content

Commit db1e59b

Browse files
Shortening the next paragraph
1 parent 348a8bb commit db1e59b

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

form/form_collections.rst

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,7 @@ In your controller, you'll create a new form from the ``TaskType``::
159159
{
160160
$task = new Task();
161161

162-
// dummy code - this is here just so that the Task has some tags
163-
// otherwise, this isn't an interesting example
162+
// dummy code - add some tags to the task to play with
164163
$tag1 = new Tag();
165164
$tag1->setName('tag1');
166165
$task->getTags()->add($tag1);
@@ -174,7 +173,7 @@ In your controller, you'll create a new form from the ``TaskType``::
174173
$form->handleRequest($request);
175174

176175
if ($form->isSubmitted() && $form->isValid()) {
177-
// ... maybe do some form processing, like saving the Task and Tag objects
176+
// ... do your form processing, like saving the Task and Tag entities
178177
}
179178

180179
return $this->render('task/new.html.twig', [
@@ -183,11 +182,8 @@ In your controller, you'll create a new form from the ``TaskType``::
183182
}
184183
}
185184

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).
185+
In the template, we need to iterate over the existing ``TagType`` forms
186+
to render them:
191187

192188
.. code-block:: html+twig
193189

@@ -196,20 +192,15 @@ zero tags when first created).
196192
{# ... #}
197193

198194
{{ form_start(form) }}
199-
{# render the task's only field: description #}
200195
{{ form_row(form.description) }}
201-
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 %}
208201
</ul>
209202
{{ form_end(form) }}
210203

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

0 commit comments

Comments
 (0)