function ShortcutLazyBuilders::lazyLinks

Same name and namespace in other branches
  1. 9 core/modules/shortcut/src/ShortcutLazyBuilders.php \Drupal\shortcut\ShortcutLazyBuilders::lazyLinks()
  2. 8.9.x core/modules/shortcut/src/ShortcutLazyBuilders.php \Drupal\shortcut\ShortcutLazyBuilders::lazyLinks()
  3. 10 core/modules/shortcut/src/ShortcutLazyBuilders.php \Drupal\shortcut\ShortcutLazyBuilders::lazyLinks()

#lazy_builder callback; builds shortcut toolbar links.

Parameters

bool $show_configure_link: Boolean to indicate whether to include the configure link or not.

Return value

array A renderable array of shortcut links.

File

core/modules/shortcut/src/ShortcutLazyBuilders.php, line 53

Class

ShortcutLazyBuilders
Lazy builders for the shortcut module.

Namespace

Drupal\shortcut

Code

public function lazyLinks(bool $show_configure_link = TRUE) {
    $shortcut_set = $this->entityTypeManager
        ->getStorage('shortcut_set')
        ->getDisplayedToUser($this->currentUser);
    $links = shortcut_renderable_links();
    $configure_link = NULL;
    if ($show_configure_link && shortcut_set_edit_access($shortcut_set)->isAllowed()) {
        $configure_link = [
            '#type' => 'link',
            '#title' => t('Edit shortcuts'),
            '#url' => Url::fromRoute('entity.shortcut_set.customize_form', [
                'shortcut_set' => $shortcut_set->id(),
            ]),
            '#options' => [
                'attributes' => [
                    'class' => [
                        'edit-shortcuts',
                    ],
                ],
            ],
        ];
    }
    $build = [
        'shortcuts' => $links,
        'configure' => $configure_link,
    ];
    $this->renderer
        ->addCacheableDependency($build, $shortcut_set);
    return $build;
}

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