function toolbar_menu_toolbar in Toolbar Menu 8
Same name and namespace in other branches
- 8.2 toolbar_menu.module \toolbar_menu_toolbar()
Implements hook_toolbar().
File
- ./
toolbar_menu.module, line 46 - Add menu entries in the Drupal Toolbar.
Code
function toolbar_menu_toolbar() {
$items = [];
/** @var \Drupal\toolbar_menu\ToolbarMenuManager $toolbar_manager */
$toolbar_manager = \Drupal::service('toolbar_menu.manager');
foreach ($toolbar_manager
->getToolbarMenuElements() as $element_id => $element) {
$items['toolbar_menu_' . $element_id] = [
'#type' => 'toolbar_item',
'tab' => [
'#type' => 'link',
'#title' => $element
->getDisplayLabel(),
'#url' => Url::fromRoute('<front>'),
'#attributes' => [
'title' => $element
->getDisplayLabel(),
'class' => [
'toolbar-icon',
'toolbar-icon-toolbar-menu',
'toolbar-icon-toolbar-menu-' . $element_id,
],
'data-drupal-subtrees' => '',
],
],
'tray' => [
'#heading' => t('@menu_label actions', [
'@menu_label' => $element
->getDisplayLabel(),
]),
'toolbar_menu_' . $element_id . '_links' => [
'#type' => 'container',
'#id' => $element
->loadMenu()
->id(),
'#pre_render' => [
'toolbar_menu_prerender_toolbar_tray',
],
'#attributes' => [
'class' => [
'toolbar-menu-administration',
],
],
],
],
'#weight' => $element
->weight(),
'#attached' => [
'library' => [
'toolbar_menu/icons',
],
],
'#cache' => [
'tags' => array_merge($element
->getCacheTags(), $element
->loadMenu()
->getCacheTags(), [
'toolbar_menu',
]),
],
];
}
return $items;
}