function MenuActiveTrail::getActiveLink
Same name in this branch
- 11.x core/lib/Drupal/Core/ProxyClass/Menu/MenuActiveTrail.php \Drupal\Core\ProxyClass\Menu\MenuActiveTrail::getActiveLink()
Same name in other branches
- 9 core/lib/Drupal/Core/Menu/MenuActiveTrail.php \Drupal\Core\Menu\MenuActiveTrail::getActiveLink()
- 8.9.x core/lib/Drupal/Core/Menu/MenuActiveTrail.php \Drupal\Core\Menu\MenuActiveTrail::getActiveLink()
- 10 core/lib/Drupal/Core/ProxyClass/Menu/MenuActiveTrail.php \Drupal\Core\ProxyClass\Menu\MenuActiveTrail::getActiveLink()
- 10 core/lib/Drupal/Core/Menu/MenuActiveTrail.php \Drupal\Core\Menu\MenuActiveTrail::getActiveLink()
Overrides MenuActiveTrailInterface::getActiveLink
1 call to MenuActiveTrail::getActiveLink()
- MenuActiveTrail::doGetActiveTrailIds in core/
lib/ Drupal/ Core/ Menu/ MenuActiveTrail.php - Helper method for ::getActiveTrailIds().
File
-
core/
lib/ Drupal/ Core/ Menu/ MenuActiveTrail.php, line 117
Class
- MenuActiveTrail
- Provides the default implementation of the active menu trail service.
Namespace
Drupal\Core\MenuCode
public function getActiveLink($menu_name = NULL) {
// Note: this is a very simple implementation. If you need more control
// over the return value, such as matching a prioritized list of menu names,
// you should substitute your own implementation for the 'menu.active_trail'
// service in the container.
// The menu links coming from the storage are already sorted by depth,
// weight and ID.
$found = NULL;
$route_name = $this->routeMatch
->getRouteName();
// On a default (not custom) 403 page the route name is NULL. On a custom
// 403 page we will get the route name for that page, so we can consider
// it a feature that a relevant menu tree may be displayed.
if ($route_name) {
$route_parameters = $this->routeMatch
->getRawParameters()
->all();
// Load links matching this route.
$links = $this->menuLinkManager
->loadLinksByRoute($route_name, $route_parameters, $menu_name);
// Select the first matching link.
if ($links) {
$found = reset($links);
}
}
return $found;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.