Skip to content

Commit 3fc64a0

Browse files
committed
Fixed code examples in cookbook/form
1 parent 586bd1f commit 3fc64a0

File tree

6 files changed

+63
-75
lines changed

6 files changed

+63
-75
lines changed

cookbook/form/create_custom_field_type.rst

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ will be called `GenderType` and the file will be stored in the default location
2020
for form fields, which is ``<BundleName>\Form\Type``. Make sure the field extends
2121
:class:`Symfony\\Component\\Form\\AbstractType`::
2222

23-
# src/Acme/DemoBundle/Form/Type/GenderType.php
23+
// src/Acme/DemoBundle/Form/Type/GenderType.php
2424
namespace Acme\DemoBundle\Form\Type;
2525

2626
use Symfony\Component\Form\AbstractType;
@@ -107,23 +107,22 @@ we want to always render it in a ``ul`` element. In your form theme template
107107
.. code-block:: html+jinja
108108

109109
{# src/Acme/DemoBundle/Resources/views/Form/fields.html.twig #}
110-
111110
{% block gender_widget %}
112-
{% spaceless %}
113-
{% if expanded %}
114-
<ul {{ block('widget_container_attributes') }}>
115-
{% for child in form %}
116-
<li>
117-
{{ form_widget(child) }}
118-
{{ form_label(child) }}
119-
</li>
120-
{% endfor %}
121-
</ul>
122-
{% else %}
123-
{# just let the choice widget render the select tag #}
124-
{{ block('choice_widget') }}
125-
{% endif %}
126-
{% endspaceless %}
111+
{% spaceless %}
112+
{% if expanded %}
113+
<ul {{ block('widget_container_attributes') }}>
114+
{% for child in form %}
115+
<li>
116+
{{ form_widget(child) }}
117+
{{ form_label(child) }}
118+
</li>
119+
{% endfor %}
120+
</ul>
121+
{% else %}
122+
{# just let the choice widget render the select tag #}
123+
{{ block('choice_widget') }}
124+
{% endif %}
125+
{% endspaceless %}
127126
{% endblock %}
128127

129128
.. note::
@@ -136,7 +135,6 @@ we want to always render it in a ``ul`` element. In your form theme template
136135
.. code-block:: yaml
137136
138137
# app/config/config.yml
139-
140138
twig:
141139
form:
142140
resources:
@@ -231,7 +229,7 @@ returned by the ``getName`` method defined earlier. We'll see the importance
231229
of this in a moment when we use the custom field type. But first, add a ``__construct``
232230
argument to ``GenderType``, which receives the gender configuration::
233231

234-
# src/Acme/DemoBundle/Form/Type/GenderType.php
232+
// src/Acme/DemoBundle/Form/Type/GenderType.php
235233
namespace Acme\DemoBundle\Form\Type;
236234
// ...
237235

@@ -276,4 +274,4 @@ Notice that instead of instantiating a new instance, we can just refer to
276274
it by the alias used in our service configuration, ``gender``. Have fun!
277275

278276
.. _`ChoiceType`: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php
279-
.. _`FieldType`: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Extension/Core/Type/FieldType.php
277+
.. _`FieldType`: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Extension/Core/Type/FieldType.php

cookbook/form/data_transformers.rst

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ was entered::
101101
Next, we create the data transformer, which does the actual conversion::
102102

103103
// src/Acme/TaskBundle/Form/DataTransformer/IssueToNumberTransformer.php
104-
105104
namespace Acme\TaskBundle\Form\DataTransformer;
106105

107106
use Symfony\Component\Form\DataTransformerInterface;
@@ -193,7 +192,6 @@ manager can be automatically injected:
193192
You can now add the type to your form by its alias as follows::
194193

195194
// src/Acme/TaskBundle/Form/Type/TaskType.php
196-
197195
namespace Acme\TaskBundle\Form\Type;
198196

199197
use Symfony\Component\Form\AbstractType;
@@ -206,8 +204,7 @@ You can now add the type to your form by its alias as follows::
206204
$builder
207205
->add('task')
208206
->add('dueDate', null, array('widget' => 'single_text'));
209-
->add('issue', 'issue_selector')
210-
;
207+
->add('issue', 'issue_selector');
211208
}
212209

213210
public function getName()

cookbook/form/dynamic_form_generation.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ How to Dynamically Generate Forms Using Form Events
77
Before jumping right into dynamic form generation, let's have a quick review
88
of what a bare form class looks like::
99

10-
//src/Acme/DemoBundle/Form/ProductType.php
10+
// src/Acme/DemoBundle/Form/ProductType.php
1111
namespace Acme\DemoBundle\Form;
1212

1313
use Symfony\Component\Form\AbstractType;
@@ -53,7 +53,7 @@ So, instead of directly adding that "name" widget via our ProductType form
5353
class, let's delegate the responsibility of creating that particular field
5454
to an Event Subscriber::
5555

56-
//src/Acme/DemoBundle/Form/ProductType.php
56+
// src/Acme/DemoBundle/Form/ProductType.php
5757
namespace Acme\DemoBundle\Form
5858

5959
use Symfony\Component\Form\AbstractType

cookbook/form/form_collections.rst

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ zero tags when first created).
199199
.. code-block:: html+jinja
200200

201201
{# src/Acme/TaskBundle/Resources/views/Task/new.html.twig #}
202+
202203
{# ... #}
203204

204205
<form action="..." method="POST" {{ form_enctype(form) }}>
@@ -220,6 +221,7 @@ zero tags when first created).
220221
.. code-block:: html+php
221222

222223
<!-- src/Acme/TaskBundle/Resources/views/Task/new.html.php -->
224+
223225
<!-- ... -->
224226

225227
<form action="..." method="POST" ...>
@@ -279,6 +281,7 @@ type expects to receive exactly two, otherwise an error will be thrown:
279281
add the ``allow_add`` option to our collection field::
280282

281283
// src/Acme/TaskBundle/Form/Type/TaskType.php
284+
282285
// ...
283286
284287
public function buildForm(FormBuilder $builder, array $options)
@@ -307,7 +310,7 @@ new "tag" forms. To render it, make the following change to your template:
307310

308311
.. code-block:: html+jinja
309312

310-
<ul class="tags" data-prototype="{{ form_widget(form.tags.vars.prototype) | e }}">
313+
<ul class="tags" data-prototype="{{ form_widget(form.tags.vars.prototype)|e }}">
311314
...
312315
</ul>
313316

@@ -333,7 +336,7 @@ new "tag" forms. To render it, make the following change to your template:
333336

334337
.. code-block:: html+jinja
335338

336-
{{ form_widget(form.tags.vars.prototype.name) | e }}
339+
{{ form_widget(form.tags.vars.prototype.name)|e }}
337340

338341
On the rendered page, the result will look something like this:
339342

@@ -424,6 +427,10 @@ new ``Tag`` objects and added to the ``tags`` property of the ``Task`` object.
424427

425428
.. code-block:: php-annotations
426429
430+
// src/Acme/TaskBundle/Entity/Task.php
431+
432+
// ...
433+
427434
/**
428435
* @ORM\ManyToMany(targetEntity="Tag", cascade={"persist"})
429436
*/
@@ -453,6 +460,7 @@ new ``Tag`` objects and added to the ``tags`` property of the ``Task`` object.
453460
is set to ``false``::
454461
455462
// src/Acme/TaskBundle/Entity/Task.php
463+
456464
// ...
457465

458466
public function setTags(ArrayCollection $tags)
@@ -467,6 +475,7 @@ new ``Tag`` objects and added to the ``tags`` property of the ``Task`` object.
467475
Inside ``Tag``, just make sure you have an ``addTask`` method::
468476

469477
// src/Acme/TaskBundle/Entity/Tag.php
478+
470479
// ...
471480

472481
public function addTask(Task $task)
@@ -490,6 +499,7 @@ The solution is similar to allowing tags to be added.
490499
Start by adding the ``allow_delete`` option in the form Type::
491500
492501
// src/Acme/TaskBundle/Form/Type/TaskType.php
502+
493503
// ...
494504
495505
public function buildForm(FormBuilder $builder, array $options)
@@ -573,6 +583,7 @@ the relationship between the removed ``Tag`` and ``Task`` object.
573583
is handling the "update" of your Task::
574584

575585
// src/Acme/TaskBundle/Controller/TaskController.php
586+
576587
// ...
577588

578589
public function editAction($id, Request $request)

0 commit comments

Comments
 (0)