예제 #1
0
 /**
  * Returns the collection of routes in the source.
  *
  * @return RouterInterface
  *   The requested link collection.
  */
 public function getSourceRoutes()
 {
     if (empty($this->sourceRoutes)) {
         $this->sourceRoutes = new Drupal7Router();
         $items = call_user_func($this->target->id() . '_menu');
         foreach ($items as $path => $item) {
             $this->sourceRoutes->addRoute(new Drupal7Route($path, $item));
         }
         // Now that all routes have been loaded, tell them to resolve their
         // hierarchical relationships.
         $this->sourceRoutes->finalize();
     }
     return $this->sourceRoutes;
 }
 /**
  * {@inheritdoc}
  */
 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;
     });
 }