class SessionWorkspaceNegotiator

Same name and namespace in other branches
  1. 9 core/modules/workspaces/src/Negotiator/SessionWorkspaceNegotiator.php \Drupal\workspaces\Negotiator\SessionWorkspaceNegotiator
  2. 8.9.x core/modules/workspaces/src/Negotiator/SessionWorkspaceNegotiator.php \Drupal\workspaces\Negotiator\SessionWorkspaceNegotiator
  3. 10 core/modules/workspaces/src/Negotiator/SessionWorkspaceNegotiator.php \Drupal\workspaces\Negotiator\SessionWorkspaceNegotiator

Defines the session workspace negotiator.

Hierarchy

Expanded class hierarchy of SessionWorkspaceNegotiator

1 string reference to 'SessionWorkspaceNegotiator'
workspaces.services.yml in core/modules/workspaces/workspaces.services.yml
core/modules/workspaces/workspaces.services.yml
1 service uses SessionWorkspaceNegotiator
workspaces.negotiator.session in core/modules/workspaces/workspaces.services.yml
Drupal\workspaces\Negotiator\SessionWorkspaceNegotiator

File

core/modules/workspaces/src/Negotiator/SessionWorkspaceNegotiator.php, line 14

Namespace

Drupal\workspaces\Negotiator
View source
class SessionWorkspaceNegotiator implements WorkspaceNegotiatorInterface, WorkspaceIdNegotiatorInterface {
  public function __construct(protected readonly AccountInterface $currentUser, protected readonly Session $session, protected readonly EntityTypeManagerInterface $entityTypeManager) {
  }
  
  /**
   * {@inheritdoc}
   */
  public function applies(Request $request) {
    // This negotiator only applies if the current user is authenticated.
    return $this->currentUser
      ->isAuthenticated();
  }
  
  /**
   * {@inheritdoc}
   */
  public function getActiveWorkspaceId(Request $request) : ?string {
    return $this->session
      ->get('active_workspace_id');
  }
  
  /**
   * {@inheritdoc}
   */
  public function getActiveWorkspace(Request $request) {
    $workspace_id = $this->getActiveWorkspaceId($request);
    if ($workspace_id && ($workspace = $this->entityTypeManager
      ->getStorage('workspace')
      ->load($workspace_id))) {
      return $workspace;
    }
    return NULL;
  }
  
  /**
   * {@inheritdoc}
   */
  public function setActiveWorkspace(WorkspaceInterface $workspace) {
    $this->session
      ->set('active_workspace_id', $workspace->id());
  }
  
  /**
   * {@inheritdoc}
   */
  public function unsetActiveWorkspace() {
    $this->session
      ->remove('active_workspace_id');
  }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
SessionWorkspaceNegotiator::applies public function Checks whether the negotiator applies to the current request or not. Overrides WorkspaceNegotiatorInterface::applies 1
SessionWorkspaceNegotiator::getActiveWorkspace public function
SessionWorkspaceNegotiator::getActiveWorkspaceId public function Performs workspace negotiation. Overrides WorkspaceIdNegotiatorInterface::getActiveWorkspaceId 1
SessionWorkspaceNegotiator::setActiveWorkspace public function Notifies the negotiator that the workspace ID returned has been accepted. Overrides WorkspaceNegotiatorInterface::setActiveWorkspace 1
SessionWorkspaceNegotiator::unsetActiveWorkspace public function Unsets the negotiated workspace. Overrides WorkspaceNegotiatorInterface::unsetActiveWorkspace 1
SessionWorkspaceNegotiator::__construct public function

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