shortcut_renderable_links

shortcut_renderable_links($shortcut_set = NULL)

Returns an array of shortcut links, suitable for rendering.

Parameters

\Drupal\shortcut\ShortcutSetInterface $shortcut_set: (optional) An object representing the set whose links will be displayed. If not provided, the user's current set will be displayed.

Return value

\Drupal\shortcut\ShortcutInterface[] An array of shortcut links, in the format returned by the menu system.

File

core/modules/shortcut/shortcut.module, line 254
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
function shortcut_renderable_links($shortcut_set = NULL) {
  $shortcut_links = array();
 
  if (!isset($shortcut_set)) {
    $shortcut_set = shortcut_current_displayed_set();
  }
 
  $cache_tags = array();
  foreach ($shortcut_set->getShortcuts() as $shortcut) {
    $shortcut = \Drupal::entityManager()->getTranslationFromContext($shortcut);
    $url = $shortcut->getUrl();
    if ($url->access()) {
      $links[$shortcut->id()] = array(
        'type' => 'link',
        'title' => $shortcut->label(),
        'url' => $shortcut->getUrl(),
      );
      $cache_tags = Cache::mergeTags($cache_tags, $shortcut->getCacheTags());
    }
  }
 
  if (!empty($links)) {
    $shortcut_links = array(
      '#theme' => 'links__toolbar_shortcuts',
      '#links' => $links,
      '#attributes' => array(
        'class' => array('toolbar-menu'),
      ),
      '#cache' => array(
        'tags' => $cache_tags,
      ),
    );
  }
 
  return $shortcut_links;
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.