function shortcut_renderable_links

Same name in other branches
  1. 7.x modules/shortcut/shortcut.module \shortcut_renderable_links()
  2. 8.9.x core/modules/shortcut/shortcut.module \shortcut_renderable_links()
  3. 10 core/modules/shortcut/shortcut.module \shortcut_renderable_links()
  4. 11.x 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()
ShortcutLazyBuilders::lazyLinks in core/modules/shortcut/src/ShortcutLazyBuilders.php
#lazy_builder callback; builds shortcut toolbar links.
ShortcutsBlock::build in core/modules/shortcut/src/Plugin/Block/ShortcutsBlock.php
Builds and returns the renderable array for this block plugin.

File

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

Code

function shortcut_renderable_links($shortcut_set = NULL) {
    $shortcut_links = [];
    if (!isset($shortcut_set)) {
        $shortcut_set = shortcut_current_displayed_set();
    }
    $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.