RoutingBundle

RoutingBundle

Both content routes and redirect routes can be administrated. When creating content routes, a tree of content documents is shown. The administrator can select a content document to bind to the route. This tree is configured with the content_basepath setting.

The root path to add routes defaults to the first entry in route_basepaths configuration of the RoutingBundle. You can overwrite this with the basepath option if you need a different base path.

Routes can also be handled in the content admin page. The admin integration provides an admin extension that allows adding routes to any route aware objects. Another extension provides a frontend link on all admin pages that objects that refer to routes.

Configuration

  • YAML
    1
    2
    3
    4
    5
    6
    7
    # app/config/config.yml
    cmf_sonata_phpcr_admin_integration:
        bundles:
            routing:
                enabled: false
                basepath: ~
                content_basepath: ~
    
  • XML
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    <!-- app/config/config.xml -->
    <?xml version="1.0" encoding="UTF-8" ?>
    <container xmlns="http://symfony.com/schema/dic/services">
        <config xmlns="http://cmf.symfony.com/schema/dic/sonata-phpcr-admin-integration">
            <bundles>
                <routing
                    enabled="false"
                    basepath="null"
                    content-basepath="null"
                />
            </bundles>
        </config>
    </container>
    
  • PHP
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    // app/config/config.php
    $container->loadFromExtension('cmf_sonata_phpcr_admin_integration', [
        'bundles' => [
            'routing' => [
                'enabled' => false,
                'basepath' => null,
                'content_basepath' => null,
            ],
        ],
    ];
    

enabled

type: bool default: false

If true, the admin classes and extensions of this package are loaded and available for Sonata Admin.

Tip

If you do not see this admin on the Sonata dashboard, you need to configure the dashboard to show the admin service in question. Read more about this in the Sonata Admin documentation.

The routing admins are cmf_sonata_phpcr_admin_integration.routing.route_admin and cmf_sonata_phpcr_admin_integration.routing.redirect_route_admin.

basepath

type: string default: first value of cmf_routing.dynamic.persistence.phpcr.route_basepaths

The path at which to create routes with Sonata admin. There can be additional route basepaths for the routing, but you will need to set up separate admin services to edit those.

content_basepath

type: string default: / or cmf_content.persistence.phpcr.content_basepath

The basepath for content objects in the PHPCR tree. This information is used to offer the correct subtree to select the target content document for a route.

If the ContentBundle is registered, this will default to cmf_content.persistence.phpcr.content_basepath. Otherwise, it defaults to / to show the whole tree.

RouteReferrersInterface Admin Extension

This bundle provides an extension to edit referring routes for content that implements the RouteReferrersInterface.

You can define the form group and tab to be used by the field this extension adds:

  • YAML
    1
    2
    3
    4
    5
    6
    7
    8
    # app/config/config.yml
    cmf_sonata_phpcr_admin_integration:
        bundles:
            routing:
                extensions:
                    referrers:
                        form_group: form.group_routing
                        form_tab: form.tab_routing
    
  • XML
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    <!-- app/config/config.xml -->
    <?xml version="2.0" encoding="UTF-8" ?>
    <container xmlns="http://symfony.com/schema/dic/services"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance"
        xsd:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
            http://cmf.symfony.com/schema/dic/sonata_admin_integration http://cmf.symfony.com/schema/dic/sonata_admin_integration/sonata_admin_integration.xsd"
    >
    
        <config xmlns="http://cmf.symfony.com/schema/dic/sonata_admin_integration">
            <bundles>
                <routing>
                    <extensions>
                        <referrers
                            form-group="form.group_routing"
                            form-tab="form.tab_routing"
                         />
                    </extensions>
            </bundles>
        </config>
    </container>
    
  • PHP
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    // app/config/config.php
    $container->loadFromExtension('cmf_sonata_phpcr_admin_integration', [
        'bundles' => [
            'routing' => [
                'extensions' => [
                    'referrers' => [
                        'form_group' => 'form.group_routing',
                        'form_tag' => 'form.tab_routing',
                    ],
                ],
            ],
        ],
    ]);
    

form_group

type: string default: form.group_routing

The name of the form group to use in the admin extension.

The caption for the group is determined by translating the group name. If you change the group, be sure to also define a translation for it.

form_tab

type: string default: form.tab_routing

The name of the form tab to use in the admin extension.

The caption for the tab is determined by translating the tab name. If you change the tab name, be sure to also define a translation for it.

Using the extension

To activate the extension in your admin classes, define the extension configuration in the sonata_admin section of your project configuration:

  • YAML
    1
    2
    3
    4
    5
    6
    7
    # app/config/config.yml
    sonata_admin:
        # ...
        extensions:
            cmf_sonata_phpcr_admin_integration.routing.extension.route_referrers:
                implements:
                    - Symfony\Cmf\Component\Routing\RouteReferrersInterface
    
  • XML
    1
    2
    3
    4
    5
    6
    7
    8
    9
    <!-- app/config/config.xml -->
    <?xml version="1.0" encoding="UTF-8" ?>
    <container xmlns="http://symfony.com/schema/dic/services">
        <config xmlns="http://sonata-project.org/schema/dic/admin">
            <extension id="cmf_sonata_phpcr_admin_integration.routing.extension.route_referrers">
                <implements>Symfony\Cmf\Component\Routing\RouteReferrersInterface</implements>
            </extension>
        </config>
    </container>
    
  • PHP
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    // app/config/config.php
    use Symfony\Cmf\Bundle\Routing\RedirectRouteInterface;
    
    $container->loadFromExtension('sonata_admin', [
        'extensions' => [
            'cmf_sonata_phpcr_admin_integration.routing.extension.route_referrers' => [
                'implements' => [
                    RouteReferrersInterface::class,
                ],
            ],
        ],
    ]);
    

See the Sonata Admin extension documentation for more information.

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.