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/ Drupal7/ RouteWrapper.php, line 96
Class
- RouteWrapper
- Encapsulates a Drupal 7 route (including the link, if any).
Namespace
Drupal\drupalmoduleupgrader\Routing\Drupal7Code
public function onRouterBuilt(RouterBuiltEvent $event) {
$this->router = $event
->getRouter();
$my_path = $this
->getPath();
$my_length = sizeof($my_path);
$my_path = (string) $my_path;
// If trying to get the parent raises an exception, we're going to
// bail out. But we don't need the parent in order to find our own
// children, so search for them before searching for the parent.
$this->children = $this->router
->filter(function (RouteWrapper $route) use ($my_path, $my_length) {
$path = $route
->getPath();
// <WTF>$path needs to be explicitly cast to a string, 'cause strPos() won't do
// it, even though trim() and similar functions will.</WTF>
return sizeof($path) == $my_length + 1 && strpos((string) $path, $my_path) === 0;
})
->ofType('MENU_LOCAL_TASK, MENU_DEFAULT_LOCAL_TASK, MENU_LOCAL_ACTION');
try {
$parent = $this
->getPath()
->getParent();
$this->parent = $this->router
->get($parent
->__toString());
} catch (\LengthException $e) {
// Because there's no parent path, we can't effectively search for siblings.
// Time to die.
return;
}
$this->siblings = $this->router
->filter(function (RouteWrapper $route) use ($parent, $my_path, $my_length) {
$path = $route
->getPath();
// <WTF>strPos(), <sarcasm>in its wisdom</sarcasm>, won't cast to string.</WTF>
return $path !== $my_path && sizeof($path) == $my_length && strpos((string) $path, (string) $parent) === 0;
});
}