<commit_before>Advanced configuration
======================

.. note::

   This article assumes you are using Symfony 4. Using Symfony 2.8 or 3
    will require to slightly modify some namespaces and paths when creating
    entities and admins.

Service Configuration
---------------------

When you create a new Admin service you can configure its dependencies,
the services which are injected by default are:

=========================     ===================================================================
Dependencies                  Service ID
=========================     ===================================================================
model_manager                 sonata.admin.manager.%manager-type%
form_contractor               sonata.admin.builder.%manager-type%_form
show_builder                  sonata.admin.builder.%manager-type%_show
list_builder                  sonata.admin.builder.%manager-type%_list
datagrid_builder              sonata.admin.builder.%manager-type%_datagrid
translator                    translator
configuration_pool            sonata.admin.pool
router                        router
validator                     validator
security_handler              sonata.admin.security.handler
menu_factory                  knp_menu.factory
route_builder                 sonata.admin.route.path_info | sonata.admin.route.path_info_slashes
label_translator_strategy     sonata.admin.label.strategy.form_component
=========================     ===================================================================

.. note::

    ``%manager-type%`` is to be replaced by the manager type (orm, doctrine_mongodb...),
    and the default route_builder depends on it.

You have 2 ways of defining the dependencies inside your services config file
(``services.xml`` or ``services.yaml``):

With a tag attribute (less verbose)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. configuration-block::

    .. code-block:: xml

        <!-- config/services.xml -->

        <service id="app.admin.project" class="App\Admin\ProjectAdmin">
            <argument />
            <argument>App\Entity\Project</argument>
            <argument />
            <tag
                name="sonata.admin"
                manager_type="orm"
                group="Project"
                label="Project"
                label_translator_strategy="sonata.admin.label.strategy.native"
                route_builder="sonata.admin.route.path_info"
                />
        </service>

    .. code-block:: yaml

        # config/services.yaml

        app.admin.project:
            class: App\Admin\ProjectAdmin
            arguments:
                - ~
                - App\Entity\Project
                - ~
            tags:
                -
                    name: sonata.admin
                    manager_type: orm
                    group: 'Project'
                    label: 'Project'
                    label_translator_strategy: 'sonata.admin.label.strategy.native'
                    route_builder: 'sonata.admin.route.path_info'

With a method call (more verbose)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. configuration-block::

    .. code-block:: xml

        <!-- config/services.xml -->

        <service id="app.admin.project" class="App\Admin\ProjectAdmin">
            <argument />
            <argument>App\Entity\Project</argument>
            <argument />
            <call method="setLabelTranslatorStrategy">
                <argument type="service" id="sonata.admin.label.strategy.native" />
            </call>
            <call method="setRouteBuilder">
                <argument type="service" id="sonata.admin.route.path_info" />
            </call>
            <tag name="sonata.admin" manager_type="orm" group="Project" label="Project" />
        </service>

    .. code-block:: yaml

        # config/services.yaml

        app.admin.project:
            class: App\Admin\ProjectAdmin
            arguments:
                - ~
                - App\Entity\Project
                - ~
            calls:
                - [setLabelTranslatorStrategy, ['@sonata.admin.label.strategy.native']]
                - [setRouteBuilder, ['@sonata.admin.route.path_info']]
            tags:
                - { name: sonata.admin, manager_type: orm, group: 'Project', label: 'Project' }

If you want to modify the service that is going to be injected, add the following code to your
application's config file:

.. configuration-block::

    .. code-block:: yaml

        # config/packages/sonata_admin.yaml

        admins:
            sonata_admin:
                sonata.order.admin.order:   # id of the admin service this setting is for
                    model_manager:          # dependency name, from the table above
                        sonata.order.admin.order.manager  # customised service id


Creating a custom RouteBuilder
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

To create your own RouteBuilder create the PHP class and register it as a service::

    namespace App\Route;

    use Sonata\AdminBundle\Builder\RouteBuilderInterface;
    use Sonata\AdminBundle\Admin\AdminInterface;
    use Sonata\AdminBundle\Route\PathInfoBuilder;
    use Sonata\AdminBundle\Route\RouteCollection;

    class EntityRouterBuilder extends PathInfoBuilder implements RouteBuilderInterface
    {
        /**
         * @param AdminInterface  $admin
         * @param RouteCollection $collection
         */
        public function build(AdminInterface $admin, RouteCollection $collection)
        {
            parent::build($admin, $collection);
<commit_msg>[Docs] use h4 instead h5 headline<commit_after>Advanced configuration
======================

.. note::

   This article assumes you are using Symfony 4. Using Symfony 2.8 or 3
    will require to slightly modify some namespaces and paths when creating
    entities and admins.

Service Configuration
---------------------

When you create a new Admin service you can configure its dependencies,
the services which are injected by default are:

=========================     ===================================================================
Dependencies                  Service ID
=========================     ===================================================================
model_manager                 sonata.admin.manager.%manager-type%
form_contractor               sonata.admin.builder.%manager-type%_form
show_builder                  sonata.admin.builder.%manager-type%_show
list_builder                  sonata.admin.builder.%manager-type%_list
datagrid_builder              sonata.admin.builder.%manager-type%_datagrid
translator                    translator
configuration_pool            sonata.admin.pool
router                        router
validator                     validator
security_handler              sonata.admin.security.handler
menu_factory                  knp_menu.factory
route_builder                 sonata.admin.route.path_info | sonata.admin.route.path_info_slashes
label_translator_strategy     sonata.admin.label.strategy.form_component
=========================     ===================================================================

.. note::

    ``%manager-type%`` is to be replaced by the manager type (orm, doctrine_mongodb...),
    and the default route_builder depends on it.

You have 2 ways of defining the dependencies inside your services config file
(``services.xml`` or ``services.yaml``):

With a tag attribute (less verbose)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. configuration-block::

    .. code-block:: xml

        <!-- config/services.xml -->

        <service id="app.admin.project" class="App\Admin\ProjectAdmin">
            <argument />
            <argument>App\Entity\Project</argument>
            <argument />
            <tag
                name="sonata.admin"
                manager_type="orm"
                group="Project"
                label="Project"
                label_translator_strategy="sonata.admin.label.strategy.native"
                route_builder="sonata.admin.route.path_info"
                />
        </service>

    .. code-block:: yaml

        # config/services.yaml

        app.admin.project:
            class: App\Admin\ProjectAdmin
            arguments:
                - ~
                - App\Entity\Project
                - ~
            tags:
                -
                    name: sonata.admin
                    manager_type: orm
                    group: 'Project'
                    label: 'Project'
                    label_translator_strategy: 'sonata.admin.label.strategy.native'
                    route_builder: 'sonata.admin.route.path_info'

With a method call (more verbose)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. configuration-block::

    .. code-block:: xml

        <!-- config/services.xml -->

        <service id="app.admin.project" class="App\Admin\ProjectAdmin">
            <argument />
            <argument>App\Entity\Project</argument>
            <argument />
            <call method="setLabelTranslatorStrategy">
                <argument type="service" id="sonata.admin.label.strategy.native" />
            </call>
            <call method="setRouteBuilder">
                <argument type="service" id="sonata.admin.route.path_info" />
            </call>
            <tag name="sonata.admin" manager_type="orm" group="Project" label="Project" />
        </service>

    .. code-block:: yaml

        # config/services.yaml

        app.admin.project:
            class: App\Admin\ProjectAdmin
            arguments:
                - ~
                - App\Entity\Project
                - ~
            calls:
                - [setLabelTranslatorStrategy, ['@sonata.admin.label.strategy.native']]
                - [setRouteBuilder, ['@sonata.admin.route.path_info']]
            tags:
                - { name: sonata.admin, manager_type: orm, group: 'Project', label: 'Project' }

If you want to modify the service that is going to be injected, add the following code to your
application's config file:

.. configuration-block::

    .. code-block:: yaml

        # config/packages/sonata_admin.yaml

        admins:
            sonata_admin:
                sonata.order.admin.order:   # id of the admin service this setting is for
                    model_manager:          # dependency name, from the table above
                        sonata.order.admin.order.manager  # customised service id


Creating a custom RouteBuilder
------------------------------

To create your own RouteBuilder create the PHP class and register it as a service::

    namespace App\Route;

    use Sonata\AdminBundle\Builder\RouteBuilderInterface;
    use Sonata\AdminBundle\Admin\AdminInterface;
    use Sonata\AdminBundle\Route\PathInfoBuilder;
    use Sonata\AdminBundle\Route\RouteCollection;

    class EntityRouterBuilder extends PathInfoBuilder implements RouteBuilderInterface
    {
        /**
         * @param AdminInterface  $admin
         * @param RouteCollection $collection
         */
        public function build(AdminInterface $admin, RouteCollection $collection)
        {
            parent::build($admin, $collection);

{'fraction_non_alphanumeric': 0.15785701487188675, 'fraction_numerical': 0.0010750761512273786, 'mean_word_length': 2.035073409461664, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4216745', 'n_tokens_mistral': 2817, 'n_tokens_neox': 2626, 'n_words': 637}