Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit 51fd613

Browse files
committed
Merge pull request #685 from symfony-cmf/custom-url-generator
documenting the custom url generator configuration
2 parents 61cf280 + 912d40b commit 51fd613

File tree

3 files changed

+57
-13
lines changed

3 files changed

+57
-13
lines changed

bundles/routing/configuration.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,15 @@ content repository service.
542542

543543
.. _reference-config-routing-locales:
544544

545+
``url_generator``
546+
~~~~~~~~~~~~~~~~~
547+
548+
**type**: ``string`` **default**: ``cmf_routing.generator``
549+
550+
Service id for the DynamicRouter to generate URLs from Route objects. Overwrite
551+
to a service implementing ``UrlGeneratorInterface`` if you need to customize that
552+
service.
553+
545554
``locales``
546555
~~~~~~~~~~~
547556

bundles/routing/dynamic.rst

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ You can configure the route enhancers that decide what controller is used to
1616
handle the request, to avoid hard coding controller names into your route
1717
documents.
1818

19+
To fully understand the capabilities of the dynamic router, read also the
20+
:doc:`routing component documentation <../../components/routing/index>`.
21+
1922
Configuration
2023
-------------
2124

@@ -617,8 +620,8 @@ See the `Sonata Admin extension documentation`_ for more information.
617620
FrontendLink Sonata Admin Extension
618621
-----------------------------------
619622

620-
This bundle provides an extension to show a button in Sonata Admin, which links on the actual
621-
frontend representation of a document. Documents which implement the ``RouteReferrersReadInterface``
623+
This bundle provides an extension to show a button in Sonata Admin, which links on the actual
624+
frontend representation of a document. Documents which implement the ``RouteReferrersReadInterface``
622625
and Routes itself (``Symfony\Component\Routing\Route``) are supported.
623626

624627
To enable the extension in your admin classes, simply define the extension
@@ -636,7 +639,7 @@ configuration in the ``sonata_admin`` section of your project configuration:
636639
implements:
637640
- Symfony\Cmf\Component\Routing\RouteReferrersReadInterface
638641
extends:
639-
- Symfony\Component\Routing\Route
642+
- Symfony\Component\Routing\Route
640643
641644
.. code-block:: xml
642645
@@ -670,19 +673,19 @@ See the `Sonata Admin extension documentation`_ for more information.
670673
Styling
671674
~~~~~~~
672675

673-
Feel free to use your own styles. The frontend link button can be customized
676+
Feel free to use your own styles. The frontend link button can be customized
674677
using the following example CSS rules:
675678

676679
.. code-block:: css
677680
678681
.sonata-admin-menu-item a.sonata-admin-frontend-link {
679682
font-weight: bold;
680683
}
681-
684+
682685
.sonata-admin-menu-item a.sonata-admin-frontend-link:before {
683686
font-family: FontAwesome;
684687
content: "\f08e";
685-
}
688+
}
686689
687690
Customize the DynamicRouter
688691
---------------------------

bundles/routing/dynamic_customize.rst

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ configuration as follows:
124124
# app/config/config.yml
125125
cmf_routing:
126126
dynamic:
127-
enabled: true
128127
route_provider_service_id: acme_demo.provider.endpoint
129128
130129
.. code-block:: xml
@@ -133,10 +132,7 @@ configuration as follows:
133132
<?xml version="1.0" encoding="UTF-8" ?>
134133
<container xmlns="http://symfony.com/schema/dic/services">
135134
<config xmlns="http://cmf.symfony.com/schema/dic/routing">
136-
<dynamic
137-
enabled="true"
138-
route-provider-service-id="acme_demo.provider.endpoint"
139-
/>
135+
<dynamic route-provider-service-id="acme_demo.provider.endpoint"/>
140136
</config>
141137
</container>
142138
@@ -145,14 +141,50 @@ configuration as follows:
145141
// app/config/config.php
146142
$container->loadFromExtension('cmf_routing', array(
147143
'dynamic' => array(
148-
'enabled' => true,
149144
'route_provider_service_id' => 'acme_demo.provider.endpoint',
150145
),
151146
));
152147
153148
Where ``acme_demo.provider.endpoint`` is the service ID of your route
154-
provider. See `Creating and configuring services in the container`_ for
149+
provider. See `Creating and configuring services in the container`_ for
155150
information on creating custom services.
156151

152+
Using a Custom URL Generator
153+
----------------------------
154+
155+
The dynamic router can also generate URLs from route objects. If you need to
156+
customize this behavior beyond what the
157+
:ref:`route generate event <components-routing-events>` allows, you can
158+
implement the ``Symfony\Component\Routing\Generator\UrlGeneratorInterface``
159+
yourself and configure that service:
160+
161+
.. configuration-block::
162+
163+
.. code-block:: yaml
164+
165+
# app/config/config.yml
166+
cmf_routing:
167+
dynamic:
168+
url_generator: routing.my_generator
169+
170+
.. code-block:: xml
171+
172+
<!-- app/config/config.xml -->
173+
<?xml version="1.0" encoding="UTF-8" ?>
174+
<container xmlns="http://symfony.com/schema/dic/services">
175+
<config xmlns="http://cmf.symfony.com/schema/dic/routing">
176+
<dynamic url-generator="routing.my_generator"/>
177+
</config>
178+
</container>
179+
180+
.. code-block:: php
181+
182+
// app/config/config.php
183+
$container->loadFromExtension('cmf_routing', array(
184+
'dynamic' => array(
185+
'url_generator' => 'routing.my_generator',
186+
),
187+
));
188+
157189
.. _`Creating and configuring services in the container`: http://symfony.com/doc/current/book/service_container.html#creating-configuring-services-in-the-container/
158190
.. _`PHPCR-ODM`: http://www.doctrine-project.org/projects/phpcr-odm.html

0 commit comments

Comments
 (0)