You are here

function toolbar_tools_menu_navigation_links in Admin Toolbar 8

Same name and namespace in other branches
  1. 8.2 admin_toolbar.module \toolbar_tools_menu_navigation_links()
  2. 3.x admin_toolbar.module \toolbar_tools_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.

1 string reference to 'toolbar_tools_menu_navigation_links'
admin_toolbar_prerender_toolbar_administration_tray in ./admin_toolbar.module
Renders the toolbar's administration tray.

File

./admin_toolbar.module, line 115
This is the module to create a drop-down menu for the core toolbar.

Code

function toolbar_tools_menu_navigation_links(array $tree) {
  foreach ($tree as $element) {
    if ($element->subtree) {
      toolbar_tools_menu_navigation_links($element->subtree);
    }
    $link = $element->link;

    // Get the non-localized title to make the icon class.
    $definition = $link
      ->getPluginDefinition();
    $element->options['attributes']['class'][] = 'toolbar-icon';
    $string = strtolower(str_replace([
      '.',
      ' ',
      '_',
    ], [
      '-',
      '-',
      '-',
    ], $definition['id']));
    $element->options['attributes']['class'][] = Html::cleanCssIdentifier('toolbar-icon-' . $string);
    $element->options['attributes']['title'] = $link
      ->getDescription();
  }
  return $tree;
}