function shortcut_renderable_links

Same name in other branches
  1. 7.x modules/shortcut/shortcut.module \shortcut_renderable_links()
  2. 9 core/modules/shortcut/shortcut.module \shortcut_renderable_links()
  3. 8.9.x core/modules/shortcut/shortcut.module \shortcut_renderable_links()
  4. 10 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.

1 call to shortcut_renderable_links()
ShortcutLazyBuilders::lazyLinks in core/modules/shortcut/src/ShortcutLazyBuilders.php
#lazy_builder callback; builds shortcut toolbar links.

File

core/modules/shortcut/shortcut.module, line 134

Code

function shortcut_renderable_links($shortcut_set = NULL) {
    $shortcut_links = [];
    if (!isset($shortcut_set)) {
        $account = \Drupal::currentUser();
        $shortcut_set = \Drupal::entityTypeManager()->getStorage('shortcut_set')
            ->getDisplayedToUser($account);
    }
    $cache_tags = [];
    foreach ($shortcut_set->getShortcuts() as $shortcut) {
        $shortcut = \Drupal::service('entity.repository')->getTranslationFromContext($shortcut);
        $url = $shortcut->getUrl();
        if ($url->access()) {
            $links[$shortcut->id()] = [
                'type' => 'link',
                'title' => $shortcut->label(),
                'url' => $shortcut->getUrl(),
            ];
            $cache_tags = Cache::mergeTags($cache_tags, $shortcut->getCacheTags());
        }
    }
    if (!empty($links)) {
        $shortcut_links = [
            '#theme' => 'links__toolbar_shortcuts',
            '#links' => $links,
            '#attributes' => [
                'class' => [
                    'toolbar-menu',
                ],
            ],
            '#cache' => [
                'tags' => $cache_tags,
            ],
        ];
    }
    return $shortcut_links;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.