function WorkspacesLazyBuilder::renderNavigationLinks

Lazy builder callback for rendering navigation links.

Return value

array A renderable array as expected by the renderer service.

File

core/modules/navigation/src/WorkspacesLazyBuilder.php, line 34

Class

WorkspacesLazyBuilder
Defines a service for workspaces #lazy_builder callbacks.

Namespace

Drupal\navigation

Code

public function renderNavigationLinks() : array {
    $active_workspace = $this->workspaceManager
        ->getActiveWorkspace();
    $url = Url::fromRoute('entity.workspace.collection', [], [
        'query' => $this->getDestinationArray(),
    ]);
    $url->setOption('attributes', [
        'class' => [
            $active_workspace ? 'toolbar-button--workspaces' : 'toolbar-button--workspaces--live',
            'use-ajax',
        ],
        'data-dialog-type' => 'dialog',
        'data-dialog-renderer' => 'off_canvas_top',
        'data-dialog-options' => Json::encode([
            'height' => 161,
            'classes' => [
                'ui-dialog' => 'workspaces-dialog',
            ],
        ]),
    ]);
    return [
        '#theme' => 'navigation_menu',
        '#title' => $this->t('Workspace'),
        '#items' => [
            [
                'title' => $active_workspace ? $active_workspace->label() : $this->t('Live'),
                'url' => $url,
                'class' => 'workspaces',
            ],
        ],
        '#attached' => [
            'library' => [
                'navigation/internal.navigation-workspaces',
                'workspaces/drupal.workspaces.off-canvas',
            ],
        ],
        '#cache' => [
            'max-age' => 0,
        ],
    ];
}

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