function WorkspaceManager::doSwitchWorkspace
Same name in other branches
- 9 core/modules/workspaces/src/WorkspaceManager.php \Drupal\workspaces\WorkspaceManager::doSwitchWorkspace()
- 10 core/modules/workspaces/src/WorkspaceManager.php \Drupal\workspaces\WorkspaceManager::doSwitchWorkspace()
- 11.x core/modules/workspaces/src/WorkspaceManager.php \Drupal\workspaces\WorkspaceManager::doSwitchWorkspace()
Switches the current workspace.
Parameters
\Drupal\workspaces\WorkspaceInterface|null $workspace: The workspace to set as active or NULL to switch out of the currently active workspace.
Throws
\Drupal\workspaces\WorkspaceAccessException Thrown when the current user doesn't have access to view the workspace.
4 calls to WorkspaceManager::doSwitchWorkspace()
- WorkspaceManager::executeInWorkspace in core/
modules/ workspaces/ src/ WorkspaceManager.php - Executes the given callback function in the context of a workspace.
- WorkspaceManager::executeOutsideWorkspace in core/
modules/ workspaces/ src/ WorkspaceManager.php - Executes the given callback function without any workspace context.
- WorkspaceManager::setActiveWorkspace in core/
modules/ workspaces/ src/ WorkspaceManager.php - Sets the active workspace via the workspace negotiators.
- WorkspaceManager::switchToLive in core/
modules/ workspaces/ src/ WorkspaceManager.php - Unsets the active workspace via the workspace negotiators.
File
-
core/
modules/ workspaces/ src/ WorkspaceManager.php, line 251
Class
- WorkspaceManager
- Provides the workspace manager.
Namespace
Drupal\workspacesCode
protected function doSwitchWorkspace($workspace) {
// If the current user doesn't have access to view the workspace, they
// shouldn't be allowed to switch to it.
if ($workspace && !$workspace->access('view')) {
$this->logger
->error('Denied access to view workspace %workspace_label for user %uid', [
'%workspace_label' => $workspace->label(),
'%uid' => $this->currentUser
->id(),
]);
throw new WorkspaceAccessException('The user does not have permission to view that workspace.');
}
$this->activeWorkspace = $workspace ?: FALSE;
// Clear the static entity cache for the supported entity types.
$cache_tags_to_invalidate = array_map(function ($entity_type_id) {
return 'entity.memory_cache:' . $entity_type_id;
}, array_keys($this->getSupportedEntityTypes()));
$this->entityMemoryCache
->invalidateTags($cache_tags_to_invalidate);
// Clear the static cache for path aliases. We can't inject the path alias
// manager service because it would create a circular dependency.
\Drupal::service('path_alias.manager')->cacheClear();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.