You are here

class SessionWorkspaceNegotiator in Multiversion 8

Hierarchy

Expanded class hierarchy of SessionWorkspaceNegotiator

1 string reference to 'SessionWorkspaceNegotiator'
multiversion.services.yml in ./multiversion.services.yml
multiversion.services.yml
1 service uses SessionWorkspaceNegotiator
workspace.negotiator.session in ./multiversion.services.yml
Drupal\multiversion\Workspace\SessionWorkspaceNegotiator

File

src/Workspace/SessionWorkspaceNegotiator.php, line 9

Namespace

Drupal\multiversion\Workspace
View source
class SessionWorkspaceNegotiator extends WorkspaceNegotiatorBase {

  /**
   * @var \Drupal\user\PrivateTempStore
   */
  protected $tempstore;

  /**
   * Constructor.
   *
   * @param \Drupal\user\PrivateTempStoreFactory $tempstore_factory
   */
  public function __construct(PrivateTempStoreFactory $tempstore_factory) {
    $this->tempstore = $tempstore_factory
      ->get('workspace.negotiator.session');
  }

  /**
   * {@inheritdoc}
   */
  public function applies(Request $request) {

    // This negotiator only applies if the current user is authenticated,
    // i.e. a session exists.
    return $this->currentUser
      ->isAuthenticated();
  }

  /**
   * {@inheritdoc}
   */
  public function getWorkspaceId(Request $request) {
    $workspace_id = $this->tempstore
      ->get('active_workspace_id');
    return $workspace_id ?: $this->container
      ->getParameter('workspace.default');
  }

  /**
   * {@inheritdoc}
   */
  public function persist(WorkspaceInterface $workspace) {
    $this->tempstore
      ->set('active_workspace_id', $workspace
      ->id());
    return TRUE;
  }

}

Members