function WorkspacesLazyBuilders::renderToolbarTab
Same name in other branches
- 11.x core/modules/workspaces/src/WorkspacesLazyBuilders.php \Drupal\workspaces\WorkspacesLazyBuilders::renderToolbarTab()
Lazy builder callback for rendering the workspace toolbar tab.
Return value
array A render array.
File
-
core/
modules/ workspaces/ src/ WorkspacesLazyBuilders.php, line 33
Class
- WorkspacesLazyBuilders
- Defines a service for workspaces #lazy_builder callbacks.
Namespace
Drupal\workspacesCode
public function renderToolbarTab() : array {
$active_workspace = $this->workspaceManager
->getActiveWorkspace();
$build = [
'#type' => 'link',
'#title' => $active_workspace ? $active_workspace->label() : $this->t('Live'),
'#url' => Url::fromRoute('entity.workspace.collection', [], [
'query' => \Drupal::destination()->getAsArray(),
]),
'#attributes' => [
'title' => t('Switch workspace'),
'class' => [
'toolbar-item',
'toolbar-icon',
'toolbar-icon-workspace',
'use-ajax',
],
'data-dialog-type' => 'dialog',
'data-dialog-renderer' => 'off_canvas_top',
'data-dialog-options' => Json::encode([
'height' => 161,
'classes' => [
'ui-dialog' => 'workspaces-dialog',
],
]),
],
'#attached' => [
'library' => [
'workspaces/drupal.workspaces.toolbar',
],
],
'#cache' => [
'max-age' => 0,
],
];
// The renderer has already added element defaults by the time the lazy
// builder is run.
// @see https://www.drupal.org/project/drupal/issues/2609250
$build += $this->elementInfo
->getInfo('link');
return $build;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.