ToolbarMenuPrerender.php in Toolbar Menu 8.2
File
src/ToolbarMenuPrerender.php
View source
<?php
namespace Drupal\toolbar_menu;
use Drupal\Core\Menu\MenuTreeParameters;
use Drupal\Core\Security\TrustedCallbackInterface;
class ToolbarMenuPrerender implements TrustedCallbackInterface {
public static function trustedCallbacks() {
return [
'prerenderToolbarTray',
];
}
public static function prerenderToolbarTray(array $element) {
$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;
}
}