Issue #2968875 by timmillwood, amateescu: Bring back the query parameter workspace negotiator
parent
44986fefc2
commit
716f73dde1
|
@ -0,0 +1,33 @@
|
|||
<?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 @@ class WorkspaceSwitcherTest extends BrowserTestBase {
|
|||
|
||||
$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 @@ class WorkspaceSwitcherTest extends BrowserTestBase {
|
|||
$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:
|
||||
|
|
Loading…
Reference in New Issue