You are here

function shortcut_renderable_links in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/shortcut/shortcut.module \shortcut_renderable_links()

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.

2 calls to shortcut_renderable_links()
ShortcutsBlock::build in core/modules/shortcut/src/Plugin/Block/ShortcutsBlock.php
Builds and returns the renderable array for this block plugin.
shortcut_toolbar in core/modules/shortcut/shortcut.module
Implements hook_toolbar().

File

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

Code

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;
}