You are here

function shortcut_toolbar in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/shortcut/shortcut.module \shortcut_toolbar()
  2. 10 core/modules/shortcut/shortcut.module \shortcut_toolbar()

Implements hook_toolbar().

File

core/modules/shortcut/shortcut.module, line 381
Allows users to manage customizable lists of shortcut links.

Code

function shortcut_toolbar() {
  $user = \Drupal::currentUser();
  $items = [];
  $items['shortcuts'] = [
    '#cache' => [
      'contexts' => [
        'user.permissions',
      ],
    ],
  ];
  if ($user
    ->hasPermission('access shortcuts')) {
    $shortcut_set = shortcut_current_displayed_set();
    $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',
            ],
          ],
        ],
      ],
      '#weight' => -10,
      '#attached' => [
        'library' => [
          'shortcut/drupal.shortcut',
        ],
      ],
    ];
  }
  return $items;
}