Commit 716f73dd authored by catch's avatar catch

Issue #2968875 by timmillwood, amateescu: Bring back the query parameter workspace negotiator

parent 44986fef
<?php
namespace Drupal\workspace\Negotiator;
use Symfony\Component\HttpFoundation\Request;
/**
* Defines the query parameter workspace negotiator.
*/
class QueryParameterWorkspaceNegotiator extends SessionWorkspaceNegotiator {
/**
* {@inheritdoc}
*/
public function applies(Request $request) {
return is_string($request->query->get('workspace')) && parent::applies($request);
}
/**
* {@inheritdoc}
*/
public function getActiveWorkspace(Request $request) {
$workspace_id = $request->query->get('workspace');
if ($workspace_id && ($workspace = $this->workspaceStorage->load($workspace_id))) {
$this->setActiveWorkspace($workspace);
return $workspace;
}
return NULL;
}
}
......@@ -19,9 +19,11 @@ class WorkspaceSwitcherTest extends BrowserTestBase {
public static $modules = ['block', 'workspace'];
/**
* Test switching workspace via the switcher block and admin page.
* {@inheritdoc}
*/
public function testSwitchingWorkspaces() {
protected function setUp() {
parent::setUp();
$permissions = [
'create workspace',
'edit own workspace',
......@@ -33,7 +35,12 @@ public function testSwitchingWorkspaces() {
$mayer = $this->drupalCreateUser($permissions);
$this->drupalLogin($mayer);
}
/**
* Test switching workspace via the switcher block and admin page.
*/
public function testSwitchingWorkspaces() {
$vultures = $this->createWorkspaceThroughUi('Vultures', 'vultures');
$this->switchToWorkspace($vultures);
......@@ -48,4 +55,21 @@ public function testSwitchingWorkspaces() {
$page->findLink($gravity->label());
}
/**
* Test switching workspace via a query parameter.
*/
public function testQueryParameterNegotiator() {
$web_assert = $this->assertSession();
// Initially the default workspace should be active.
$web_assert->elementContains('css', '.block-workspace-switcher', 'Live');
// When adding a query parameter the workspace will be switched.
$this->drupalGet('<front>', ['query' => ['workspace' => 'stage']]);
$web_assert->elementContains('css', '.block-workspace-switcher', 'Stage');
// The workspace switching via query parameter should persist.
$this->drupalGet('<front>');
$web_assert->elementContains('css', '.block-workspace-switcher', 'Stage');
}
}
......@@ -15,6 +15,11 @@ services:
workspace.negotiator.session:
class: Drupal\workspace\Negotiator\SessionWorkspaceNegotiator
arguments: ['@current_user', '@session', '@entity_type.manager']
tags:
- { name: workspace_negotiator, priority: 50 }
workspace.negotiator.query_parameter:
class: Drupal\workspace\Negotiator\QueryParameterWorkspaceNegotiator
parent: workspace.negotiator.session
tags:
- { name: workspace_negotiator, priority: 100 }
cache_context.workspace:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment