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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | 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 ; } |
Please login to continue.