Skip to content
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

WIP: Default injected services #3319

Closed
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Resources/config/core.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<argument />
</service>

<!-- Services used to format the label, default is sonata.admin.label.strategy.noop -->
<!-- Services used to format the label, default is sonata.admin.label.strategy.native -->
<service id="sonata.admin.label.strategy.bc" class="Sonata\AdminBundle\Translator\BCLabelTranslatorStrategy" />
<service id="sonata.admin.label.strategy.native" class="Sonata\AdminBundle\Translator\NativeLabelTranslatorStrategy" />
<service id="sonata.admin.label.strategy.noop" class="Sonata\AdminBundle\Translator\NoopLabelTranslatorStrategy" />
Expand Down
20 changes: 20 additions & 0 deletions Resources/doc/reference/action_create_edit.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@ To do:
- options available when adding fields, inc custom templates
- link to the field_types document for more details about specific field types

Global options
~~~~~~~~~~~~~~

There are some options about create and edit actions you might want to set
globally rather than on an admin-by-admin basis. This can done with the bundle
configuration.

.. code-block:: yaml

sonata_admin:
options:
label_translator_strategy: sonata.admin.label.strategy.native

``options.label_translator_strategy``
Defaults to ``sonata.admin.label.strategy.native``. The value should be the
id of a service that implements
``Sonata\AdminBundle\Translator\LabelTranslatorStrategyInterface``. For
more information, see
`the dedicated document <reference/label_translator_strategy.rst>`_

FormGroup options
~~~~~~~~~~~~~~~~~

Expand Down
38 changes: 30 additions & 8 deletions Resources/doc/reference/translation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -134,25 +134,47 @@ labels are generated by using a simple rule:

isValid => Is Valid

A label translator strategy processes labels so that they can follow a given
naming policy. It implements
``Sonata\AdminBundle\Translator\LabelTranslatorStrategyInterface``, which
consists of one method, with the following signature :
``public function getLabel($label, $context = '', $type = '');``. In the context
of a form with an ``isValid`` field, it is called as follows :
``$strategy->getLabel('isValid', 'form', 'label')``


The ``AdminBundle`` comes with different key label generation strategies:

* ``sonata.admin.label.strategy.native``: DEFAULT - Makes the string human readable
``isValid`` => ``Is Valid``
* ``sonata.admin.label.strategy.form_component``: The default behavior from the Form Component
``isValid`` => ``Isvalid``
* ``sonata.admin.label.strategy.underscore``: Changes the name into a token suitable
for translation by prepending "form.label" to an underscored version of the field name
``sonata.admin.label.strategy.native``
DEFAULT - Makes the string human readable ``isValid`` => ``Is Valid``

``sonata.admin.label.strategy.form_component``
The default behavior from the Form Component
``isValid`` => ``Isvalid``

``sonata.admin.label.strategy.underscore``
Changes the name into a token suitable for translation by prepending
"form.label" to an underscored version of the field name.
``isValid`` => ``form.label_is_valid``
* ``sonata.admin.label.strategy.noop``: does not alter the string
``isValid`` => ``isValid``

``sonata.admin.label.strategy.noop``
does not alter the string ``isValid`` => ``isValid``

``sonata.admin.label.strategy.bc``
Backwards-Compatible label translator strategy. Labels are as they where
before label translator strategies where introduced.
``isValid`` => ``Isvalid``
Avoid it if you are creating a new project.

``sonata.admin.label.strategy.underscore`` will be better for i18n applications
and ``sonata.admin.label.strategy.native`` will be better for native (single) language
apps based on the field name. It is reasonable to start with the ``native`` strategy
and then, when the application needs to be translated using generic keys, the
configuration can be switched to ``underscore``.

If you cannot find a strategy that fits your use case, you can easily implement
and use your own. If you do, consider contributing your strategy.

The strategy can be quickly configured when the Admin class is registered in
the Container:

Expand Down