function ShortcutNavigationLazyBuilder::lazyLinks

Same name and namespace in other branches
  1. main core/modules/shortcut/src/ShortcutNavigationLazyBuilder.php \Drupal\shortcut\ShortcutNavigationLazyBuilder::lazyLinks()

The #lazy_builder callback; builds shortcut navigation links.

Attributes

#[TrustedCallback]

Parameters

string $label: (Optional) The links label. Defaults to "Shortcuts".

Return value

array A renderable array of shortcut links.

File

core/modules/shortcut/src/ShortcutNavigationLazyBuilder.php, line 36

Class

ShortcutNavigationLazyBuilder
Lazy Builders for Navigation shortcuts links.

Namespace

Drupal\shortcut

Code

public function lazyLinks(string $label = 'Shortcuts') {
  $shortcut_links = $this->shortcutLazyBuilder
    ->lazyLinks();
  if (empty($shortcut_links['shortcuts']['#links'])) {
    return [
      '#cache' => $shortcut_links['#cache'],
    ];
  }
  $shortcuts_items = [
    [
      'title' => $label,
      'class' => 'shortcuts',
      'icon' => [
        'icon_id' => 'shortcuts',
      ],
      'below' => $shortcut_links['shortcuts']['#links'],
    ],
  ];
  return [
    '#theme' => 'navigation_menu',
    '#menu_name' => 'shortcuts',
    '#title' => $label,
    '#items' => $shortcuts_items,
    '#cache' => $shortcut_links['#cache'],
  ];
}

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