@@ -157,8 +157,7 @@ In your controller, you'll create a new form from the ``TaskType``::
157157 {
158158 $task = new Task();
159159
160- // dummy code - this is here just so that the Task has some tags
161- // otherwise, this isn't an interesting example
160+ // dummy code - add some tags to the task to play with
162161 $tag1 = new Tag();
163162 $tag1->setName('tag1');
164163 $task->getTags()->add($tag1);
@@ -172,7 +171,7 @@ In your controller, you'll create a new form from the ``TaskType``::
172171 $form->handleRequest($request);
173172
174173 if ($form->isSubmitted() && $form->isValid()) {
175- // ... maybe do some form processing, like saving the Task and Tag objects
174+ // ... do your form processing, like saving the Task and Tag entities
176175 }
177176
178177 return $this->render('task/new.html.twig', [
@@ -181,11 +180,8 @@ In your controller, you'll create a new form from the ``TaskType``::
181180 }
182181 }
183182
184- The corresponding template is now able to render both the ``description ``
185- field for the task form as well as all the ``TagType `` forms for any tags
186- that are already related to this ``Task ``. In the above controller, I added
187- some dummy code so that you can see this in action (since a ``Task `` has
188- zero tags when first created).
183+ In the template, we need to iterate over the existing ``TagType `` forms
184+ to render them:
189185
190186.. code-block :: html+twig
191187
@@ -194,20 +190,15 @@ zero tags when first created).
194190 {# ... #}
195191
196192 {{ form_start(form) }}
197- {# render the task's only field: description #}
198193 {{ form_row(form.description) }}
199-
200194 <h3>Tags</h3>
201195 <ul class="tags">
202- {# iterate over each existing tag and render its only field: name #}
203196 {% for tag in form.tags %}
204197 <li>{{ form_row(tag.name) }}</li>
205198 {% endfor %}
206199 </ul>
207200 {{ form_end(form) }}
208201
209- {# ... #}
210-
211202When the user submits the form, the submitted data for the ``tags `` field are
212203used to construct an ``ArrayCollection `` of ``Tag `` objects, which is then set
213204on the ``tag `` field of the ``Task `` instance.
0 commit comments