function toolbar_menu_navigation_links in Drupal 8
Same name and namespace in other branches
- 7 modules/toolbar/toolbar.module \toolbar_menu_navigation_links()
- 9 core/modules/toolbar/toolbar.module \toolbar_menu_navigation_links()
Adds toolbar-specific attributes to the menu link tree.
Parameters
\Drupal\Core\Menu\MenuLinkTreeElement[] $tree: The menu link tree to manipulate.
Return value
\Drupal\Core\Menu\MenuLinkTreeElement[] The manipulated menu link tree.
2 string references to 'toolbar_menu_navigation_links'
- ToolbarController::preRenderAdministrationTray in core/
modules/ toolbar/ src/ Controller/ ToolbarController.php - Renders the toolbar's administration tray.
- ToolbarController::preRenderGetRenderedSubtrees in core/
modules/ toolbar/ src/ Controller/ ToolbarController.php - #pre_render callback for toolbar_get_rendered_subtrees().
File
- core/
modules/ toolbar/ toolbar.module, line 239 - Administration toolbar for quick access to top level administration items.
Code
function toolbar_menu_navigation_links(array $tree) {
foreach ($tree as $element) {
if ($element->subtree) {
toolbar_menu_navigation_links($element->subtree);
}
// Make sure we have a path specific ID in place, so we can attach icons
// and behaviors to the menu links.
$link = $element->link;
$url = $link
->getUrlObject();
if (!$url
->isRouted()) {
// This is an unusual case, so just get a distinct, safe string.
$id = substr(Crypt::hashBase64($url
->getUri()), 0, 16);
}
else {
$id = str_replace([
'.',
'<',
'>',
], [
'-',
'',
'',
], $url
->getRouteName());
}
// Get the non-localized title to make the icon class.
$definition = $link
->getPluginDefinition();
$element->options['attributes']['id'] = 'toolbar-link-' . $id;
$element->options['attributes']['class'][] = 'toolbar-icon';
$element->options['attributes']['class'][] = 'toolbar-icon-' . strtolower(str_replace([
'.',
' ',
'_',
], [
'-',
'-',
'-',
], $definition['id']));
$element->options['attributes']['title'] = $link
->getDescription();
}
return $tree;
}