Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 91c6267

Browse filesBrowse files
committed
[cookbook][form] Tweaking custom field type article per comments from @stof
1 parent b9f1e0b commit 91c6267
Copy full SHA for 91c6267

File tree

Expand file treeCollapse file tree

1 file changed

+8
-9
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+8
-9
lines changed

‎cookbook/form/create_custom_field_type.rst

Copy file name to clipboardExpand all lines: cookbook/form/create_custom_field_type.rst
+8-9Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ In order to create the custom field type, first we have to create the class
1818
representing the field. In our situation the class holding the field type
1919
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
21-
``AbstractType``::
21+
:class:`Symfony\\Component\\Form\\AbstractType`::
2222

2323
# src/Acme/DemoBundle/Form/Type/GenderType.php
2424
namespace Acme\DemoBundle\Form\Type;
@@ -65,7 +65,7 @@ important:
6565
you use to setup *your* forms, and it works the same here.
6666

6767
* ``buildView()`` - This method is used to set any extra variables you'll
68-
need when rendering your field in a template. For example, in ``ChoiceType``,
68+
need when rendering your field in a template. For example, in `ChoiceType`_,
6969
a ``multiple`` variable is set and used in the template to set (or not
7070
set) the ``multiple`` attribute on the ``select`` field. See `Creating a Template for the Field`_
7171
for more details.
@@ -82,9 +82,9 @@ important:
8282
Also, if you need to modify the "view" of any of your child types from
8383
your parent type, use the ``buildViewBottomUp()`` method.
8484

85-
The ``getName()`` method returns an identifier which is used to prevent conflicts
86-
with other types. Other than needing to be unique, this method isn't very
87-
important.
85+
The ``getName()`` method returns an identifier which should be unique in
86+
your application. This is used in various places, such as when customizing
87+
how your form type will be rendered.
8888

8989
The goal of our field was to extend the choice type to enable selection of
9090
a gender. This is achieved by fixing the ``choices`` to a list of possible
@@ -107,7 +107,6 @@ 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/Form/fields.html.twig #}
110-
{% use 'form_div_layout.html.twig' with choice_widget %}
111110

112111
{% block gender_widget %}
113112
{% spaceless %}
@@ -227,9 +226,9 @@ the ``genders`` parameter value as the first argument to its to-be-created
227226
Make sure the services file is being imported. See :ref:`service-container-imports-directive`
228227
for details.
229228

230-
Be sure that the ``alias`` tag corresponds with the value returned by the
231-
``getName`` method defined earlier. We'll see the importance of this in a
232-
moment when we use the custom field type. But first, add a ``__construct``
229+
Be sure that the ``alias`` attribute of the tag corresponds with the value
230+
returned by the ``getName`` method defined earlier. We'll see the importance
231+
of this in a moment when we use the custom field type. But first, add a ``__construct``
233232
argument to ``GenderType``, which receives the gender configuration::
234233

235234
# src/Acme/DemoBundle/Form/Type/GenderType.php

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.