public function RouteWrapper::onRouterBuilt in Drupal 7 to 8/9 Module Upgrader 8
Same name in this branch
- 8 src/Routing/Drupal7/RouteWrapper.php \Drupal\drupalmoduleupgrader\Routing\Drupal7\RouteWrapper::onRouterBuilt()
- 8 src/Routing/Drupal8/RouteWrapper.php \Drupal\drupalmoduleupgrader\Routing\Drupal8\RouteWrapper::onRouterBuilt()
React to the router (i.e., the collection of routes defined by the module) being completely built.
Parameters
RouterBuiltEvent $event: The event object.
Overrides RouteWrapperInterface::onRouterBuilt
File
- src/
Routing/ Drupal8/ RouteWrapper.php, line 101
Class
- RouteWrapper
- Wraps around a Symfony Route object, providing helper methods.
Namespace
Drupal\drupalmoduleupgrader\Routing\Drupal8Code
public function onRouterBuilt(RouterBuiltEvent $event) {
$this->router = $event
->getRouter();
try {
$parent = $this
->getPath()
->getParent()
->__toString();
} catch (\LengthException $e) {
return;
}
// First, search the injected router for the parent route.
foreach ($this->router as $route) {
if ($route
->getPath() == $parent) {
$this->parent = $route;
}
}
// Next, search the core route provider if no parent was found.
if (empty($this->parent)) {
$parents = $this->routeProvider
->getRoutesByPattern($parent)
->getIterator();
if (sizeof($parents) > 0) {
$this->parent = new static($parents
->key(), $parents
->current(), $this->routeProvider);
}
}
}