Skip to content

Added a note about PHP extension and Symfony Form types extension #11017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions form/create_custom_field_type.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ Defining the Field Type
In order to create the custom field type, first you have to create the class
representing the field. In this situation the class holding the field type
will be called ``ShippingType`` and the file will be stored in the default location
for form fields, which is ``<BundleName>\Form\Type``. Make sure the field extends
:class:`Symfony\\Component\\Form\\AbstractType`::
for form fields, which is ``<BundleName>\Form\Type``.

All field types must implement the :class:`Symfony\\Component\\Form\\FormTypeInterface`,
but you should instead extend from :class:`Symfony\\Component\\Form\\AbstractType`,
which already implements that interface and provides some utilities::

// src/AppBundle/Form/Type/ShippingType.php
namespace AppBundle\Form\Type;
Expand Down Expand Up @@ -54,8 +57,17 @@ for form fields, which is ``<BundleName>\Form\Type``. Make sure the field extend
Here, the return value of the ``getParent()`` function indicates that you're
extending the ``ChoiceType`` field. This means that, by default, you inherit
all of the logic and rendering of that field type. To see some of the logic,
check out the `ChoiceType`_ class. There are three methods that are particularly
important:
check out the `ChoiceType`_ class.

.. note::

The PHP class extension mechanism and the Symfony form field extension
mechanism are not the same. The parent type returned in ``getParent()`` is
what Symfony uses to build and manage the field type. Making the PHP class
extend from ``AbstractType`` is only a convenience way of implementing the
required ``FormTypeInterface``.

There are three methods that are particularly important:

.. _form-type-methods-explanation:

Expand Down