function ShortcutHooks::toolbar
Implements hook_toolbar().
File
-
core/
modules/ shortcut/ src/ Hook/ ShortcutHooks.php, line 61
Class
- ShortcutHooks
- Hook implementations for shortcut.
Namespace
Drupal\shortcut\HookCode
public function toolbar() {
$user = \Drupal::currentUser();
$items = [];
$items['shortcuts'] = [
'#cache' => [
'contexts' => [
'user.permissions',
],
],
];
if ($user->hasPermission('access shortcuts')) {
$shortcut_set = \Drupal::entityTypeManager()->getStorage('shortcut_set')
->getDisplayedToUser($user);
$items['shortcuts'] += [
'#type' => 'toolbar_item',
'tab' => [
'#type' => 'link',
'#title' => t('Shortcuts'),
'#url' => $shortcut_set->toUrl('collection'),
'#attributes' => [
'title' => t('Shortcuts'),
'class' => [
'toolbar-icon',
'toolbar-icon-shortcut',
],
],
],
'tray' => [
'#heading' => t('User-defined shortcuts'),
'children' => [
'#lazy_builder' => [
'shortcut.lazy_builders:lazyLinks',
[],
],
'#create_placeholder' => TRUE,
'#cache' => [
'keys' => [
'shortcut_set_toolbar_links',
],
'contexts' => [
'user',
],
],
'#lazy_builder_preview' => [
'#markup' => '<a href="#" class="toolbar-tray-lazy-placeholder-link"> </a>',
],
],
],
'#weight' => -10,
'#attached' => [
'library' => [
'shortcut/drupal.shortcut',
],
],
];
}
return $items;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.