SessionWorkspaceNegotiator.php in Multiversion 8
File
src/Workspace/SessionWorkspaceNegotiator.php
View source
<?php
namespace Drupal\multiversion\Workspace;
use Drupal\multiversion\Entity\WorkspaceInterface;
use Drupal\user\PrivateTempStoreFactory;
use Symfony\Component\HttpFoundation\Request;
class SessionWorkspaceNegotiator extends WorkspaceNegotiatorBase {
protected $tempstore;
public function __construct(PrivateTempStoreFactory $tempstore_factory) {
$this->tempstore = $tempstore_factory
->get('workspace.negotiator.session');
}
public function applies(Request $request) {
return $this->currentUser
->isAuthenticated();
}
public function getWorkspaceId(Request $request) {
$workspace_id = $this->tempstore
->get('active_workspace_id');
return $workspace_id ?: $this->container
->getParameter('workspace.default');
}
public function persist(WorkspaceInterface $workspace) {
$this->tempstore
->set('active_workspace_id', $workspace
->id());
return TRUE;
}
}