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

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
2016-10-29 09:43:00
Comments
Leave a Comment

Please login to continue.