You are here

public function WorkspaceManager::setActiveWorkspace in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/workspaces/src/WorkspaceManager.php \Drupal\workspaces\WorkspaceManager::setActiveWorkspace()

Sets the active workspace via the workspace negotiators.

Parameters

\Drupal\workspaces\WorkspaceInterface $workspace: The workspace to set as active.

Return value

$this

Throws

\Drupal\workspaces\WorkspaceAccessException Thrown when the current user doesn't have access to view the workspace.

Overrides WorkspaceManagerInterface::setActiveWorkspace

File

core/modules/workspaces/src/WorkspaceManager.php, line 200

Class

WorkspaceManager
Provides the workspace manager.

Namespace

Drupal\workspaces

Code

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;
}