function NavigationHooks::navigationWorkspaces

Implements hook_navigation_content_top().

File

core/modules/navigation/src/Hook/NavigationHooks.php, line 224

Class

NavigationHooks
Hook implementations for navigation.

Namespace

Drupal\navigation\Hook

Code

public function navigationWorkspaces() : array {
    // This navigation item requires the Workspaces UI module.
    if (!\Drupal::moduleHandler()->moduleExists('workspaces_ui')) {
        return [];
    }
    $current_user = \Drupal::currentUser();
    if (!$current_user->hasPermission('administer workspaces') && !$current_user->hasPermission('view own workspace') && !$current_user->hasPermission('view any workspace')) {
        return [];
    }
    return [
        'workspace' => [
            // @phpstan-ignore-next-line
'#lazy_builder' => [
                'navigation.workspaces_lazy_builders:renderNavigationLinks',
                [],
            ],
            '#create_placeholder' => TRUE,
            '#lazy_builder_preview' => [
                '#type' => 'component',
                '#component' => 'navigation:toolbar-button',
                '#props' => [
                    'html_tag' => 'a',
                    'text' => $this->t('Workspace'),
                ],
            ],
            '#weight' => -1000,
        ],
    ];
}

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