function WorkspaceManager::getActiveWorkspace

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

Overrides WorkspaceManagerInterface::getActiveWorkspace

3 calls to WorkspaceManager::getActiveWorkspace()
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::hasActiveWorkspace in core/modules/workspaces/src/WorkspaceManager.php
Determines whether a workspace is active in the current request.

File

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

Class

WorkspaceManager
Provides the workspace manager.

Namespace

Drupal\workspaces

Code

public function getActiveWorkspace() {
    if (!isset($this->activeWorkspace)) {
        $request = $this->requestStack
            ->getCurrentRequest();
        foreach ($this->negotiatorIds as $negotiator_id) {
            $negotiator = $this->classResolver
                ->getInstanceFromDefinition($negotiator_id);
            if ($negotiator->applies($request)) {
                // By default, 'view' access is checked when a workspace is activated,
                // but it should also be checked when retrieving the currently active
                // workspace.
                if (($negotiated_workspace = $negotiator->getActiveWorkspace($request)) && $negotiated_workspace->access('view')) {
                    $active_workspace = $negotiated_workspace;
                    break;
                }
            }
        }
        // If no negotiator was able to determine the active workspace, default to
        // the live version of the site.
        $this->activeWorkspace = $active_workspace ?? FALSE;
    }
    return $this->activeWorkspace;
}

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