function WorkspaceManager::setActiveWorkspace

Same name and namespace in other branches
  1. 9 core/modules/workspaces/src/WorkspaceManager.php \Drupal\workspaces\WorkspaceManager::setActiveWorkspace()
  2. 8.9.x core/modules/workspaces/src/WorkspaceManager.php \Drupal\workspaces\WorkspaceManager::setActiveWorkspace()
  3. 10 core/modules/workspaces/src/WorkspaceManager.php \Drupal\workspaces\WorkspaceManager::setActiveWorkspace()

Sets the active workspace.

Parameters

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

bool $persist: (optional) Whether to persist this workspace in the first applicable negotiator. Defaults to TRUE.

Return value

$this

Overrides WorkspaceManagerInterface::setActiveWorkspace

File

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

Class

WorkspaceManager
Provides the workspace manager.

Namespace

Drupal\workspaces

Code

public function setActiveWorkspace(WorkspaceInterface $workspace) {
  $persist = func_num_args() < 2 || func_get_arg(1);
  $this->doSwitchWorkspace($workspace);
  // Set the workspace on the first applicable negotiator.
  if ($persist) {
    $request = $this->requestStack
      ->getCurrentRequest();
    foreach ($this->negotiators as $negotiator) {
      if ($negotiator->applies($request)) {
        $negotiator->setActiveWorkspace($workspace);
        break;

      }
    }
  }
  return $this;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.