function shortcut_toolbar
Same name in other branches
- 9 core/modules/shortcut/shortcut.module \shortcut_toolbar()
- 8.9.x core/modules/shortcut/shortcut.module \shortcut_toolbar()
- 11.x core/modules/shortcut/shortcut.module \shortcut_toolbar()
Implements hook_toolbar().
File
-
core/
modules/ shortcut/ shortcut.module, line 330
Code
function shortcut_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.