You are here

function toolbar_menu_prerender_toolbar_tray in Toolbar Menu 8

Same name and namespace in other branches
  1. 8.2 toolbar_menu.module \toolbar_menu_prerender_toolbar_tray()

Pre-render the toolbar_menu tray element.

Parameters

array $element: The tray element to pre-render.

Return value

array The pre-rendered tray element.

1 string reference to 'toolbar_menu_prerender_toolbar_tray'
toolbar_menu_toolbar in ./toolbar_menu.module
Implements hook_toolbar().

File

./toolbar_menu.module, line 102
Add menu entries in the Drupal Toolbar.

Code

function toolbar_menu_prerender_toolbar_tray(array $element) {

  /** @var \Drupal\toolbar\Menu\ToolbarMenuLinkTree $menu_tree */
  $menu_tree = \Drupal::service('toolbar.menu_tree');
  $parameters = new MenuTreeParameters();
  $parameters
    ->excludeRoot()
    ->onlyEnabledLinks();
  $tree = $menu_tree
    ->load($element['#id'], $parameters);
  $manipulators = [
    [
      'callable' => 'menu.default_tree_manipulators:checkAccess',
    ],
    [
      'callable' => 'menu.default_tree_manipulators:generateIndexAndSort',
    ],
    [
      'callable' => 'toolbar_menu.menu_link_tree_manipulators:addIcons',
    ],
  ];
  $tree = $menu_tree
    ->transform($tree, $manipulators);
  $element['toolbar_menu_' . $element['#id']] = $menu_tree
    ->build($tree);
  return $element;
}