class WorkspacesLazyBuilder
Defines a service for workspaces #lazy_builder callbacks.
@internal
Hierarchy
- class \Drupal\navigation\WorkspacesLazyBuilder uses \Drupal\Core\Routing\RedirectDestinationTrait, \Drupal\Core\StringTranslation\StringTranslationTrait
Expanded class hierarchy of WorkspacesLazyBuilder
File
-
core/
modules/ navigation/ src/ WorkspacesLazyBuilder.php, line 19
Namespace
Drupal\navigationView source
final class WorkspacesLazyBuilder {
use RedirectDestinationTrait;
use StringTranslationTrait;
public function __construct(WorkspaceManagerInterface $workspaceManager) {
}
/**
* Lazy builder callback for rendering navigation links.
*
* @return array
* A renderable array as expected by the renderer service.
*/
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,
],
];
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overrides |
---|---|---|---|---|
RedirectDestinationTrait::$redirectDestination | protected | property | The redirect destination service. | 2 |
RedirectDestinationTrait::getDestinationArray | protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait::getRedirectDestination | protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait::setRedirectDestination | public | function | Sets the redirect destination service. | |
StringTranslationTrait::$stringTranslation | protected | property | The string translation service. | 3 |
StringTranslationTrait::formatPlural | protected | function | Formats a string containing a count of items. | |
StringTranslationTrait::getNumberOfPlurals | protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait::getStringTranslation | protected | function | Gets the string translation service. | |
StringTranslationTrait::setStringTranslation | public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait::t | protected | function | Translates a string to the current language or to a given language. | 1 |
WorkspacesLazyBuilder::renderNavigationLinks | public | function | Lazy builder callback for rendering navigation links. | |
WorkspacesLazyBuilder::__construct | public | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.