shortcut_toolbar()
Implements hook_toolbar().
File
- core/modules/shortcut/shortcut.module, line 372
- Allows users to manage customizable lists of shortcut links.
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | 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.