function 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.
- WorkspaceManager::switchToLive in core/
modules/ workspaces/ src/ WorkspaceManager.php - Unsets the active workspace.
File
-
core/
modules/ workspaces/ src/ WorkspaceManager.php, line 151
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, except in CLI processes.
if ($workspace && PHP_SAPI !== 'cli' && !$workspace->access('view')) {
throw new WorkspaceAccessException('The user does not have permission to view that workspace.');
}
$previous_workspace = $this->activeWorkspace ?: NULL;
$this->activeWorkspace = $workspace ?: FALSE;
$event = new WorkspaceSwitchEvent($this->activeWorkspace ?: NULL, $previous_workspace);
($this->eventDispatcher)()
->dispatch($event);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.