@@ -157,8 +157,7 @@ In your controller, you'll create a new form from the ``TaskType``::
157
157
{
158
158
$task = new Task();
159
159
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
162
161
$tag1 = new Tag();
163
162
$tag1->setName('tag1');
164
163
$task->getTags()->add($tag1);
@@ -172,7 +171,7 @@ In your controller, you'll create a new form from the ``TaskType``::
172
171
$form->handleRequest($request);
173
172
174
173
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
176
175
}
177
176
178
177
return $this->render('task/new.html.twig', [
@@ -181,11 +180,8 @@ In your controller, you'll create a new form from the ``TaskType``::
181
180
}
182
181
}
183
182
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:
189
185
190
186
.. code-block :: html+twig
191
187
@@ -194,20 +190,15 @@ zero tags when first created).
194
190
{# ... #}
195
191
196
192
{{ form_start(form) }}
197
- {# render the task's only field: description #}
198
193
{{ form_row(form.description) }}
199
-
200
194
<h3>Tags</h3>
201
195
<ul class="tags">
202
- {# iterate over each existing tag and render its only field: name #}
203
196
{% for tag in form.tags %}
204
197
<li>{{ form_row(tag.name) }}</li>
205
198
{% endfor %}
206
199
</ul>
207
200
{{ form_end(form) }}
208
201
209
- {# ... #}
210
-
211
202
When the user submits the form, the submitted data for the ``tags `` field are
212
203
used to construct an ``ArrayCollection `` of ``Tag `` objects, which is then set
213
204
on the ``tag `` field of the ``Task `` instance.
0 commit comments