+ $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) {