Skip to content

Mentioned that form related services can now be private #7823

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 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions form/create_custom_field_type.rst
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,10 @@ the ``genders`` parameter value as the first argument to its to-be-created
Make sure the services file is being imported. See :ref:`service-container-imports-directive`
for details.

.. versionadded:: 3.3
Prior to Symfony 3.3, you needed to define form type services as ``public``.
Starting from Symfony 3.3, you can also define them as ``private``.

First, add a ``__construct`` method to ``GenderType``, which receives the gender
configuration::

Expand Down
12 changes: 8 additions & 4 deletions form/create_form_type_extension.rst
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,16 @@ The ``extended_type`` key of the tag is the type of field that this extension sh
be applied to. In your case, as you want to extend the ``Symfony\Component\Form\Extension\Core\Type\FileType``
field type, you will use that as the ``extended_type``.

.. versionadded:: 3.3
Prior to Symfony 3.3, you needed to define form extension services as ``public``.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"[...] define type extension services [...]"

This is needed because there are also form extensions, but we do not register them.

Starting from Symfony 3.3, you can also define them as ``private``.

.. tip::

There is an optional tag attribute called ``priority``, which
defaults to ``0`` and controls the order in which the form
type extensions are loaded (the higher the priority, the earlier
an extension is loaded). This is useful when you need to guarantee
There is an optional tag attribute called ``priority``, which
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CS fixes should be back ported in 2.7, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. I've reverted all those changes to avoid conflicts. Thanks!

defaults to ``0`` and controls the order in which the form
type extensions are loaded (the higher the priority, the earlier
an extension is loaded). This is useful when you need to guarantee
that one extension is loaded before or after another extension.

.. versionadded:: 3.2
Expand Down
5 changes: 5 additions & 0 deletions form/data_transformers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,16 @@ Define the form type as a service in your configuration files.
)
->addTag('form.type')
;

.. tip::

For more information about defining form types as services, read
:doc:`register your form type as a service </form/form_dependencies>`.

.. versionadded:: 3.3
Prior to Symfony 3.3, you needed to define form type services as ``public``.
Starting from Symfony 3.3, you can also define them as ``private``.

Now, you can easily use your ``TaskType``::

// e.g. in a controller somewhere
Expand Down
4 changes: 4 additions & 0 deletions form/dynamic_form_modification.rst
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,10 @@ you need to register it as a service and tag it with :ref:`form.type <dic-tags-f

$container->setDefinition('app.form.friend_message', $definition);

.. versionadded:: 3.3
Prior to Symfony 3.3, you needed to define form type services as ``public``.
Starting from Symfony 3.3, you can also define them as ``private``.

In a controller that extends the :class:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller`
class, you can simply call::

Expand Down
6 changes: 5 additions & 1 deletion form/form_dependencies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Suppose you need to access the ``doctrine.orm.entity_manager`` service so that y
can make a query. First, add this as an argument to your form class::

// src/AppBundle/Form/TaskType.php

use Doctrine\ORM\EntityManager;
// ...

Expand Down Expand Up @@ -136,6 +136,10 @@ Next, register this as a service and tag it with ``form.type``:
->addTag('form.type')
;

.. versionadded:: 3.3
Prior to Symfony 3.3, you needed to define form type services as ``public``.
Starting from Symfony 3.3, you can also define them as ``private``.

That's it! Your controller - where you create the form - doesn't need to change
at all: Symfony is smart enough to load the ``TaskType`` from the container.

Expand Down
4 changes: 4 additions & 0 deletions form/type_guesser.rst
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ creating a service and tagging it as ``form.type_guesser``:
->addTag('form.type_guesser')
;

.. versionadded:: 3.3
Prior to Symfony 3.3, you needed to define type guesser services as ``public``.
Starting from Symfony 3.3, you can also define them as ``private``.

.. sidebar:: Registering a Type Guesser in the Component

If you're using the Form component standalone in your PHP project, use
Expand Down