I have defined a custom dynamic route that works, but isn't ideal:
/**
* Defines dynamic routes.
*/
class GuideUnitRoutes {
/**
* {@inheritdoc}
*/
public function routes() {
$route_collection = new RouteCollection();
$route = new Route(
"/guide_name/{guide_id}/{child}",
[
'_controller' => '\Drupal\guides\Controller\GuidesUnitController::view',
'_title' => 'Hello',
],
[
'guide_id' => '\\w+',
'child' => '\\w+',
'_permission' => 'access content',
]
);
$route_collection->add("guide.child", $route);
$route_collection->setMethods(['GET']);
return $route_collection;
}
}
If I define it to be ideal, it stops working:
/**
* Defines dynamic routes.
*/
class GuideUnitRoutes {
/**
* {@inheritdoc}
*/
public function routes() {
$route_collection = new RouteCollection();
$route = new Route(
"/guide_name-{guide_id}/{child}",
[
'_controller' => '\Drupal\guides\Controller\GuidesUnitController::view',
'_title' => 'Hello',
],
[
'guide_id' => '\\w+',
'child' => '\\w+',
'_permission' => 'access content',
]
);
$route_collection->add("guide.child", $route);
$route_collection->setMethods(['GET']);
return $route_collection;
}
}
The route that works is guide_name/foo/bar
while guide_name-foo/bar
doesn't work. I would like to know why.
Reading the Symfony docs it looks like this should be a problem. But for some reason Drupal isn't liking this. Is there an undocumented (or maybe a document that I missed) that forces tokens to be delimitated with /
. right now if I change the -
to a /
and reload the same route it works.