diff --git a/core/modules/workspaces/src/WorkspaceManager.php b/core/modules/workspaces/src/WorkspaceManager.php index 1052717..0fe39f5 100644 --- a/core/modules/workspaces/src/WorkspaceManager.php +++ b/core/modules/workspaces/src/WorkspaceManager.php @@ -166,7 +166,32 @@ public function getActiveWorkspace() { /** * {@inheritdoc} */ - public function setActiveWorkspace(WorkspaceInterface $workspace, $persist = TRUE) { + public function setActiveWorkspace(WorkspaceInterface $workspace) { + $this->doSwitchWorkspace($workspace); + + // Set the workspace on the proper negotiator. + $request = $this->requestStack->getCurrentRequest(); + foreach ($this->negotiatorIds as $negotiator_id) { + $negotiator = $this->classResolver->getInstanceFromDefinition($negotiator_id); + if ($negotiator->applies($request)) { + $negotiator->setActiveWorkspace($workspace); + break; + } + } + + return $this; + } + + /** + * Switches the current workspace. + * + * @param \Drupal\workspaces\WorkspaceInterface $workspace + * The workspace to set as active. + * + * @throws \Drupal\workspaces\WorkspaceAccessException + * Thrown when the current user doesn't have access to view the workspace. + */ + protected function doSwitchWorkspace(WorkspaceInterface $workspace) { // If the current user doesn't have access to view the workspace, they // shouldn't be allowed to switch to it. if (!$workspace->access('view') && !$workspace->isDefaultWorkspace()) { @@ -179,24 +204,10 @@ public function setActiveWorkspace(WorkspaceInterface $workspace, $persist = TRU $this->activeWorkspace = $workspace; - // Set the workspace on the proper negotiator. - if ($persist) { - $request = $this->requestStack->getCurrentRequest(); - foreach ($this->negotiatorIds as $negotiator_id) { - $negotiator = $this->classResolver->getInstanceFromDefinition($negotiator_id); - if ($negotiator->applies($request)) { - $negotiator->setActiveWorkspace($workspace); - break; - } - } - } - $supported_entity_types = $this->getSupportedEntityTypes(); foreach ($supported_entity_types as $supported_entity_type) { $this->entityTypeManager->getStorage($supported_entity_type->id())->resetCache(); } - - return $this; } /** @@ -211,9 +222,9 @@ public function executeInWorkspace($workspace_id, callable $function) { } $previous_active_workspace = $this->getActiveWorkspace(); - $this->setActiveWorkspace($workspace, FALSE); + $this->doSwitchWorkspace($workspace); $result = $function(); - $this->setActiveWorkspace($previous_active_workspace, FALSE); + $this->doSwitchWorkspace($previous_active_workspace); return $result; } diff --git a/core/modules/workspaces/src/WorkspaceManagerInterface.php b/core/modules/workspaces/src/WorkspaceManagerInterface.php index b7a7339..006a2bd 100644 --- a/core/modules/workspaces/src/WorkspaceManagerInterface.php +++ b/core/modules/workspaces/src/WorkspaceManagerInterface.php @@ -41,16 +41,13 @@ public function getActiveWorkspace(); * * @param \Drupal\workspaces\WorkspaceInterface $workspace * The workspace to set as active. - * @param bool $persist - * (optional) Whether the new active workspace should be persisted by the - * workspace negotiator. Defaults to TRUE. * * @return $this * * @throws \Drupal\workspaces\WorkspaceAccessException * Thrown when the current user doesn't have access to view the workspace. */ - public function setActiveWorkspace(WorkspaceInterface $workspace, $persist = TRUE); + public function setActiveWorkspace(WorkspaceInterface $workspace); /** * Executes the given callback function in the context of a workspace.