function NavigationShortcutsBlock::build

Same name in other branches
  1. 10 core/modules/navigation/src/Plugin/Block/NavigationShortcutsBlock.php \Drupal\navigation\Plugin\Block\NavigationShortcutsBlock::build()

Overrides BlockPluginInterface::build

File

core/modules/navigation/src/Plugin/Block/NavigationShortcutsBlock.php, line 68

Class

NavigationShortcutsBlock
Defines a shortcuts navigation block class.

Namespace

Drupal\navigation\Plugin\Block

Code

public function build() : array {
    // This navigation block requires shortcut module. Once the plugin is moved
    // to the module, this should not be necessary.
    if (!$this->moduleHandler
        ->moduleExists('shortcut')) {
        return [];
    }
    return [
        'shortcuts' => [
            // @phpstan-ignore-next-line
'#lazy_builder' => [
                'navigation.shortcut_lazy_builder:lazyLinks',
                [
                    $this->configuration['label'],
                ],
            ],
            '#create_placeholder' => TRUE,
            '#cache' => [
                'keys' => [
                    'shortcut_set_navigation_links',
                ],
                'contexts' => [
                    'user',
                ],
            ],
            '#lazy_builder_preview' => [
                '#markup' => '<a href="#" class="toolbar-tray-lazy-placeholder-link">&nbsp;</a>',
            ],
        ],
    ];
}

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