function toolbar_menu_navigation_links

toolbar_menu_navigation_links(array $tree)

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.

File

core/modules/toolbar/toolbar.module, line 250
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(array('.', '<', '>'), array('-', '', ''), $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(array('.', ' ', '_'), array('-', '-', '-'), $definition['id']));
    $element->options['attributes']['title'] = $link->getDescription();
  }
  return $tree;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!toolbar!toolbar.module/function/toolbar_menu_navigation_links/8.1.x