public function MenuLink::getRoute

Returns the Route object associated with this link, if any.

Return value

\Symfony\Component\Routing\Route|null The route object for this menu link, or NULL if there isn't one.

Overrides MenuLinkInterface::getRoute

File

drupal/core/modules/menu_link/lib/Drupal/menu_link/Plugin/Core/Entity/MenuLink.php, line 286
Contains \Drupal\menu_link\Plugin\Core\Entity\MenuLink.

Class

MenuLink
Defines the menu link entity class.

Namespace

Drupal\menu_link\Plugin\Core\Entity

Code

public function getRoute() {
  if (!$this->route_name) {
    return NULL;
  }
  if (!$this->routeObject instanceof Route) {
    $route_provider = drupal_container()
      ->get('router.route_provider');
    $this->routeObject = $route_provider
      ->getRouteByName($this->route_name);
  }
  return $this->routeObject;
}