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

Commit 5d96f9c

Browse files
committed
Merge pull request #597 from symfony-cmf/ensure_cms_routes_is_created
as the initializer is only run when sonata is present, ensure users create /cms/routes themselves
2 parents 28bd76b + 94f0b17 commit 5d96f9c

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

book/routing.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ follows::
453453
use Doctrine\Common\Persistence\ObjectManager;
454454
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\Route;
455455
use Symfony\Cmf\Bundle\ContentBundle\Doctrine\Phpcr\StaticContent;
456+
use PHPCR\Util\NodeHelper;
456457

457458
class LoadRoutingData implements FixtureInterface
458459
{
@@ -466,6 +467,8 @@ follows::
466467
throw new \RuntimeException("Fixture requires a PHPCR ODM DocumentManager instance, instance of '$class' given.");
467468
}
468469

470+
NodeHelper::createPath($session, '/cms/routes');
471+
469472
$route = new Route();
470473
$route->setParentDocument($dm->find(null, '/cms/routes'));
471474
$route->setName('projects');
@@ -491,6 +494,15 @@ follows::
491494
This will give you a document that matches the URL ``/projects/<number>`` but
492495
also ``/projects`` as there is a default for the id parameter.
493496

497+
.. caution::
498+
499+
As you can see, the code explicitely creates the ``/cms/routes`` path.
500+
The RoutingBundle only creates this path automatically if the Sonata Admin
501+
was enabled in the routing configuration using an :ref:`initializer
502+
<phpcr-odm-repository-initializers>`. Otherwise, it'll assume you do
503+
something yourself to create the path (by configuring an initializer or
504+
doing it in a fixture like this).
505+
494506
Because you defined the ``{id}`` route parameter, your controller can expect an
495507
``$id`` parameter. Additionally, because you called setRouteContent on the
496508
route, your controller can expect the ``$contentDocument`` parameter.

bundles/routing/configuration.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,13 @@ is not what you want, as the created node is of type 'Generic' and sometimes thi
441441
already needs to be a route (for the homepage). Set this to false to disable the
442442
initializer when you create your nodes your self (e.g. using Alice_).
443443

444+
.. caution::
445+
446+
Initializers are forced to be disabled when Sonata Admin is not enabled.
447+
In such cases, you might have multiple route basepaths which are created
448+
by other sources. If the route basepath isn't created by another source,
449+
you have to configure an :ref:`initializer <phpcr-odm-repository-initializers>`.
450+
444451
orm
445452
"""
446453

0 commit comments

Comments
 (0)