function WorkspaceManager::getActiveWorkspace
Same name in other branches
- 9 core/modules/workspaces/src/WorkspaceManager.php \Drupal\workspaces\WorkspaceManager::getActiveWorkspace()
- 8.9.x core/modules/workspaces/src/WorkspaceManager.php \Drupal\workspaces\WorkspaceManager::getActiveWorkspace()
- 10 core/modules/workspaces/src/WorkspaceManager.php \Drupal\workspaces\WorkspaceManager::getActiveWorkspace()
3 calls to WorkspaceManager::getActiveWorkspace()
- WorkspaceManager::executeInWorkspace in core/
modules/ workspaces/ src/ WorkspaceManager.php - WorkspaceManager::executeOutsideWorkspace in core/
modules/ workspaces/ src/ WorkspaceManager.php - WorkspaceManager::hasActiveWorkspace in core/
modules/ workspaces/ src/ WorkspaceManager.php
File
-
core/
modules/ workspaces/ src/ WorkspaceManager.php, line 42
Class
- WorkspaceManager
- Provides the workspace manager.
Namespace
Drupal\workspacesCode
public function getActiveWorkspace() {
if (!isset($this->activeWorkspace)) {
$request = $this->requestStack
->getCurrentRequest();
foreach ($this->negotiatorIds as $negotiator_id) {
/** @var \Drupal\workspaces\Negotiator\WorkspaceIdNegotiatorInterface $negotiator */
$negotiator = $this->classResolver
->getInstanceFromDefinition($negotiator_id);
if ($negotiator->applies($request)) {
if ($workspace_id = $negotiator->getActiveWorkspaceId($request)) {
/** @var \Drupal\workspaces\WorkspaceInterface $negotiated_workspace */
$negotiated_workspace = $this->entityTypeManager
->getStorage('workspace')
->load($workspace_id);
}
// By default, 'view' access is checked when a workspace is activated,
// but it should also be checked when retrieving the currently active
// workspace.
if (isset($negotiated_workspace) && $negotiated_workspace->access('view')) {
// Notify the negotiator that its workspace has been selected.
$negotiator->setActiveWorkspace($negotiated_workspace);
$active_workspace = $negotiated_workspace;
break;
}
}
}
// If no negotiator was able to provide a valid workspace, default to the
// live version of the site.
$this->activeWorkspace = $active_workspace ?? FALSE;
}
return $this->activeWorkspace;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.