Skip to content

Commit

Permalink
Merge branch '2.8'
Browse files Browse the repository at this point in the history
* 2.8:
  Finding more old form references
  Remove note about request service, which is not used anymore
  Remove information about request scpoe
  • Loading branch information
weaverryan committed Nov 30, 2015
2 parents 7bb2785 + 4ad3bce commit 35ae50c
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 88 deletions.
2 changes: 1 addition & 1 deletion best_practices/forms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ You can also
:ref:`register your form type as a service <form-cookbook-form-field-service>`.
But this is *not* recommended unless you plan to reuse the new form type in many
places or embed it in other forms directly or via the
:doc:`collection type </reference/forms/types/collection>`.
:doc:`CollectionType </reference/forms/types/collection>`.

For most forms that are used only to edit or create something, registering
the form as a service is over-kill, and makes it more difficult to figure
Expand Down
6 changes: 3 additions & 3 deletions book/forms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ Field Type Options

Each field type has a number of options that can be used to configure it.
For example, the ``dueDate`` field is currently being rendered as 3 select
boxes. However, the :doc:`date field </reference/forms/types/date>` can be
boxes. However, the :doc:`DateType </reference/forms/types/date>` can be
configured to be rendered as a single text box (where the user would enter
the date as a string in the box)::

Expand Down Expand Up @@ -1430,7 +1430,7 @@ form with many ``Product`` sub-forms). This is done by using the ``collection``
field type.

For more information see the ":doc:`/cookbook/form/form_collections`" cookbook
entry and the :doc:`collection </reference/forms/types/collection>` field type reference.
entry and the :doc:`CollectionType </reference/forms/types/collection>` reference.

.. index::
single: Forms; Theming
Expand Down Expand Up @@ -1964,7 +1964,7 @@ Learn more from the Cookbook
----------------------------

* :doc:`/cookbook/doctrine/file_uploads`
* :doc:`File Field Reference </reference/forms/types/file>`
* :doc:`FileType Reference </reference/forms/types/file>`
* :doc:`Creating Custom Field Types </cookbook/form/create_custom_field_type>`
* :doc:`/cookbook/form/form_customization`
* :doc:`/cookbook/form/dynamic_form_modification`
Expand Down
63 changes: 0 additions & 63 deletions cookbook/console/console_command.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,69 +101,6 @@ service container. In other words, you have access to any configured service::
// ...
}

However, due to the :doc:`container scopes </cookbook/service_container/scopes>` this
code doesn't work for some services. For instance, if you try to get the ``request``
service or any other service related to it, you'll get the following error:

.. code-block:: text
You cannot create a service ("request") of an inactive scope ("request").
Consider the following example that uses the ``translator`` service to
translate some contents using a console command::

protected function execute(InputInterface $input, OutputInterface $output)
{
$name = $input->getArgument('name');
$translator = $this->getContainer()->get('translator');
if ($name) {
$output->writeln(
$translator->trans('Hello %name%!', array('%name%' => $name))
);
} else {
$output->writeln($translator->trans('Hello!'));
}
}

If you dig into the Translator component classes, you'll see that the ``request``
service is required to get the locale into which the contents are translated::

// vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php
public function getLocale()
{
if (null === $this->locale && $this->container->isScopeActive('request')
&& $this->container->has('request')) {
$this->locale = $this->container->get('request')->getLocale();
}

return $this->locale;
}

Therefore, when using the ``translator`` service inside a command, you'll get the
previous *"You cannot create a service of an inactive scope"* error message.
The solution in this case is as easy as setting the locale value explicitly
before translating contents::

protected function execute(InputInterface $input, OutputInterface $output)
{
$name = $input->getArgument('name');
$locale = $input->getArgument('locale');

$translator = $this->getContainer()->get('translator');
$translator->setLocale($locale);

if ($name) {
$output->writeln(
$translator->trans('Hello %name%!', array('%name%' => $name))
);
} else {
$output->writeln($translator->trans('Hello!'));
}
}

However, for other services the solution might be more complex. For more details,
see :doc:`/cookbook/service_container/scopes`.

Invoking other Commands
-----------------------

Expand Down
4 changes: 2 additions & 2 deletions cookbook/doctrine/file_uploads.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ How to Handle File Uploads with Doctrine
Handling file uploads with Doctrine entities is no different than handling
any other file upload. In other words, you're free to move the file in your
controller after handling a form submission. For examples of how to do this,
see the :doc:`file type reference </reference/forms/types/file>` page.
see the :doc:`FileType reference </reference/forms/types/file>` page.

If you choose to, you can also integrate the file upload into your entity
lifecycle (i.e. creation, update and removal). In this case, as your entity
Expand Down Expand Up @@ -98,7 +98,7 @@ file.
.. tip::

If you have not done so already, you should probably read the
:doc:`file </reference/forms/types/file>` type documentation first to
:doc:`FileType </reference/forms/types/file>` documentation first to
understand how the basic upload process works.

.. note::
Expand Down
2 changes: 1 addition & 1 deletion cookbook/form/data_transformers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ How to Use Data Transformers

Data transformers are used to translate the data for a field into a format that can
be displayed in a form (and back on submit). They're already used internally for
many field types. For example, the :doc:`date field type </reference/forms/types/date>`
many field types. For example, the :doc:`DateType </reference/forms/types/date>` field
can be rendered as a ``yyyy-MM-dd``-formatted input textbox. Internally, a data transformer
converts the starting ``DateTime`` value of the field into the ``yyyy-MM-dd`` string
to render the form, and then back into a ``DateTime`` object on submit.
Expand Down
2 changes: 1 addition & 1 deletion cookbook/form/form_collections.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ goal is to allow the tags of a ``Task`` to be modified right inside the task
form itself, create a form for the ``Task`` class.

Notice that you embed a collection of ``TagType`` forms using the
:doc:`collection </reference/forms/types/collection>` field type::
:doc:`CollectionType </reference/forms/types/collection>` field::

// src/AppBundle/Form/Type/TaskType.php
namespace AppBundle\Form\Type;
Expand Down
10 changes: 0 additions & 10 deletions cookbook/templating/twig_extension.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,6 @@ Now you must let the Service Container know about your newly created Twig Extens
->setPublic(false)
->addTag('twig.extension');
.. note::

Keep in mind that Twig Extensions are not lazily loaded. This means that
there's a higher chance that you'll get a
:class:`Symfony\\Component\\DependencyInjection\\Exception\\ServiceCircularReferenceException`
or a
:class:`Symfony\\Component\\DependencyInjection\\Exception\\ScopeWideningInjectionException`
if any services (or your Twig Extension in this case) are dependent on
the request service. For more information take a look at :doc:`/cookbook/service_container/scopes`.

Using the custom Extension
--------------------------

Expand Down
6 changes: 3 additions & 3 deletions reference/constraints/File.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Validates that a value is a valid "file", which can be one of the following:
* A valid :class:`Symfony\\Component\\HttpFoundation\\File\\File` object
(including objects of class :class:`Symfony\\Component\\HttpFoundation\\File\\UploadedFile`).

This constraint is commonly used in forms with the :doc:`file </reference/forms/types/file>`
form type.
This constraint is commonly used in forms with the :doc:`FileType </reference/forms/types/file>`
form field.

.. tip::

Expand Down Expand Up @@ -41,7 +41,7 @@ Basic Usage
-----------

This constraint is most commonly used on a property that will be rendered
in a form as a :doc:`file </reference/forms/types/file>` form type. For
in a form as a :doc:`FileType </reference/forms/types/file>` field. For
example, suppose you're creating an author form where you can upload a "bio"
PDF for the author. In your form, the ``bioFile`` property would be a ``file``
type. The ``Author`` class might look as follows::
Expand Down
2 changes: 1 addition & 1 deletion reference/constraints/Image.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Basic Usage
-----------

This constraint is most commonly used on a property that will be rendered
in a form as a :doc:`file </reference/forms/types/file>` form type. For
in a form as a :doc:`FileType </reference/forms/types/file>` field. For
example, suppose you're creating an author form where you can upload a
"headshot" image for the author. In your form, the ``headshot`` property
would be a ``file`` type. The ``Author`` class might look as follows::
Expand Down
4 changes: 2 additions & 2 deletions reference/forms/types/options/by_reference.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ If you set ``by_reference`` to false, submitting looks like this::
So, all that ``by_reference=false`` really does is force the framework to
call the setter on the parent object.

Similarly, if you're using the :doc:`collection</reference/forms/types/collection>`
form type where your underlying collection data is an object (like with
Similarly, if you're using the :doc:`CollectionType </reference/forms/types/collection>`
field where your underlying collection data is an object (like with
Doctrine's ``ArrayCollection``), then ``by_reference`` must be set to ``false``
if you need the adder and remover (e.g. ``addAuthor()`` and ``removeAuthor()``)
to be called.
2 changes: 1 addition & 1 deletion reference/forms/types/options/invalid_message.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This is the validation error message that's used if the data entered into
this field doesn't make sense (i.e. fails validation).

This might happen, for example, if the user enters a nonsense string into
a :doc:`time</reference/forms/types/time>` field that cannot be converted
a :doc:`TimeType </reference/forms/types/time>` field that cannot be converted
into a real time or if the user enters a string (e.g. ``apple``) into a
number field.

Expand Down

0 comments on commit 35ae50c

Please sign in to comment.