admin_toolbar.module in Zircon Profile 8
Same filename and directory in other branches
File
modules/admin_toolbar/admin_toolbar.moduleView source
<?php
use Drupal\Core\Menu\MenuTreeParameters;
/**
* Implements hook_toolbar_alter().
*/
function admin_toolbar_toolbar_alter(&$items) {
$items['administration']['tray']['toolbar_administration']['#pre_render'] = array(
'admin_toolbar_prerender_toolbar_administration_tray',
);
$items['administration']['#attached']['library'][] = 'admin_toolbar/toolbar.tree';
}
/**
* Renders the toolbar's administration tray.
* This is a clone of core's toolbar_prerender_toolbar_administration_tray()
* function, which uses setMaxDepth(4) instead of setTopLevelOnly()
* @param array $element
* A renderable array.
*
* @return array
* The updated renderable array.
*
* @see toolbar_prerender_toolbar_administration_tray()
*/
function admin_toolbar_prerender_toolbar_administration_tray(array $element) {
$menu_tree = \Drupal::service('toolbar.menu_tree');
$parameters = new MenuTreeParameters();
$parameters
->setRoot('system.admin')
->excludeRoot()
->setMaxDepth(4)
->onlyEnabledLinks();
$tree = $menu_tree
->load(NULL, $parameters);
$manipulators = array(
array(
'callable' => 'menu.default_tree_manipulators:checkAccess',
),
array(
'callable' => 'menu.default_tree_manipulators:generateIndexAndSort',
),
array(
'callable' => 'toolbar_menu_navigation_links',
),
);
$tree = $menu_tree
->transform($tree, $manipulators);
$element['administration_menu'] = $menu_tree
->build($tree);
return $element;
}
Functions
Name | Description |
---|---|
admin_toolbar_prerender_toolbar_administration_tray | Renders the toolbar's administration tray. This is a clone of core's toolbar_prerender_toolbar_administration_tray() function, which uses setMaxDepth(4) instead of setTopLevelOnly() |
admin_toolbar_toolbar_alter | Implements hook_toolbar_alter(). |