You are here

function admin_toolbar_prerender_toolbar_administration_tray in Admin Toolbar 8

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().

Parameters

array $element: A renderable array.

Return value

array The updated renderable array.

See also

toolbar_prerender_toolbar_administration_tray()

1 string reference to 'admin_toolbar_prerender_toolbar_administration_tray'
admin_toolbar_toolbar_alter in ./admin_toolbar.module
Implements hook_toolbar_alter().

File

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

Code

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 = [
    [
      'callable' => 'menu.default_tree_manipulators:checkAccess',
    ],
    [
      'callable' => 'menu.default_tree_manipulators:generateIndexAndSort',
    ],
    [
      'callable' => 'toolbar_tools_menu_navigation_links',
    ],
  ];
  $tree = $menu_tree
    ->transform($tree, $manipulators);
  $element['administration_menu'] = $menu_tree
    ->build($tree);
  return $element;
}