function shortcut_toolbar

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

Implements hook_toolbar().

File

core/modules/shortcut/shortcut.module, line 263

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">&nbsp;</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.