name = $name; $this->route = $route; $this->routeProvider = $route_provider ? $route_provider: \Drupal::service('router.route_provider'); $this->path = new PathUtility($route->getPath()); } /** * Forwards unknown function calls to the wrapped Route. */ public function __call($method, array $arguments) { return call_user_func_array([ $this->route, $method ], $arguments); } /** * {@inheritdoc} */ public function getIdentifier() { return $this->name; } /** * {@inheritdoc} */ public function getPath() { return $this->path; } /** * {@inheritdoc} */ public function hasParent() { return isset($this->parent); } /** * {@inheritdoc} */ public function getParent() { return $this->parent; } /** * {@inheritdoc} */ public function unwrap() { return $this->route; } /** * {@inheritdoc} */ 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); } } } }