class ToolbarMenuPrerender in Toolbar Menu 8.2
Defines a service for toolbar menu prerender elements.
Hierarchy
- class \Drupal\toolbar_menu\ToolbarMenuPrerender implements TrustedCallbackInterface
Expanded class hierarchy of ToolbarMenuPrerender
1 file declares its use of ToolbarMenuPrerender
- toolbar_menu.module in ./
toolbar_menu.module - Add menu entries in the Drupal Toolbar.
File
- src/
ToolbarMenuPrerender.php, line 11
Namespace
Drupal\toolbar_menuView source
class ToolbarMenuPrerender implements TrustedCallbackInterface {
/**
* {@inheritdoc}
*/
public static function trustedCallbacks() {
return [
'prerenderToolbarTray',
];
}
/**
* Pre-render the toolbar_menu tray element.
*
* @param array $element
* The tray element to pre-render.
*
* @return array
* The pre-rendered tray element.
*/
public static function prerenderToolbarTray(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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ToolbarMenuPrerender:: |
public static | function | Pre-render the toolbar_menu tray element. | |
ToolbarMenuPrerender:: |
public static | function |
Lists the trusted callbacks provided by the implementing class. Overrides TrustedCallbackInterface:: |
|
TrustedCallbackInterface:: |
constant | Untrusted callbacks throw exceptions. | ||
TrustedCallbackInterface:: |
constant | Untrusted callbacks trigger silenced E_USER_DEPRECATION errors. | ||
TrustedCallbackInterface:: |
constant | Untrusted callbacks trigger E_USER_WARNING errors. |