class ShortcutLazyBuilder

Lazy Builders for Navigation shortcuts links.

@internal The navigation module is experimental.

Hierarchy

Expanded class hierarchy of ShortcutLazyBuilder

See also

\Drupal\shortcut\ShortcutLazyBuilders

File

core/modules/navigation/src/ShortcutLazyBuilder.php, line 16

Namespace

Drupal\navigation
View source
final class ShortcutLazyBuilder implements TrustedCallbackInterface {
    
    /**
     * Constructs a ShortcutLazyBuilders object.
     *
     * @param \Drupal\shortcut\ShortcutLazyBuilders $shortcutLazyBuilder
     *   The original shortcuts lazy builder service.
     */
    public function __construct(ShortcutLazyBuilders $shortcutLazyBuilder) {
    }
    
    /**
     * {@inheritdoc}
     */
    public static function trustedCallbacks() {
        return [
            'lazyLinks',
        ];
    }
    
    /**
     * The #lazy_builder callback; builds shortcut navigation links.
     *
     * @param string $label
     *   (Optional) The links label. Defaults to "Shortcuts".
     *
     * @return array
     *   A renderable array of shortcut links.
     */
    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',
                'below' => $shortcut_links['shortcuts']['#links'],
            ],
        ];
        return [
            '#theme' => 'navigation_menu',
            '#menu_name' => 'shortcuts',
            '#title' => $label,
            '#items' => $shortcuts_items,
            '#cache' => $shortcut_links['#cache'],
        ];
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
ShortcutLazyBuilder::lazyLinks public function The #lazy_builder callback; builds shortcut navigation links.
ShortcutLazyBuilder::trustedCallbacks public static function Lists the trusted callbacks provided by the implementing class. Overrides TrustedCallbackInterface::trustedCallbacks
ShortcutLazyBuilder::__construct public function Constructs a ShortcutLazyBuilders object.
TrustedCallbackInterface::THROW_EXCEPTION constant Untrusted callbacks throw exceptions.
TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION constant Untrusted callbacks trigger silenced E_USER_DEPRECATION errors.

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