shortcut_toolbar()
Implements hook_toolbar().
File
- core/modules/shortcut/shortcut.module, line 372
- Allows users to manage customizable lists of shortcut links.
Code
function shortcut_toolbar() { $user = \Drupal::currentUser(); $items = []; $items['shortcuts'] = [ '#cache' => [ 'contexts' => [ // Cacheable per user, because each user can have their own shortcut // set, even if they cannot create or select a shortcut set, because // an administrator may have assigned a non-default shortcut set. 'user', ], ], ]; if ($user->hasPermission('access shortcuts')) { $links = shortcut_renderable_links(); $shortcut_set = shortcut_current_displayed_set(); \Drupal::service('renderer')->addCacheableDependency($items['shortcuts'], $shortcut_set); $configure_link = NULL; if (shortcut_set_edit_access($shortcut_set)->isAllowed()) { $configure_link = array( '#type' => 'link', '#title' => t('Edit shortcuts'), '#url' => Url::fromRoute('entity.shortcut_set.customize_form', ['shortcut_set' => $shortcut_set->id()]), '#options' => array('attributes' => array('class' => array('edit-shortcuts'))), ); } if (!empty($links) || !empty($configure_link)) { $items['shortcuts'] += array( '#type' => 'toolbar_item', 'tab' => array( '#type' => 'link', '#title' => t('Shortcuts'), '#url' => $shortcut_set->urlInfo('collection'), '#attributes' => array( 'title' => t('Shortcuts'), 'class' => array('toolbar-icon', 'toolbar-icon-shortcut'), ), ), 'tray' => array( '#heading' => t('User-defined shortcuts'), 'shortcuts' => $links, 'configure' => $configure_link, ), '#weight' => -10, '#attached' => array( 'library' => array( 'shortcut/drupal.shortcut', ), ), ); } } return $items; }
Please login to continue.