Skip to content
Snippets Groups Projects
Commit c2d897e7 authored by Gábor Hojtsy's avatar Gábor Hojtsy
Browse files

Issue #2984938 by vijaycs85, amateescu, jeqq, timmillwood, larowlan, Wim...

Issue #2984938 by vijaycs85, amateescu, jeqq, timmillwood, larowlan, Wim Leers, alexpott: Remember the page you were on and take you back there when switching Workspaces
parent 83a6e955
No related branches found
No related tags found
No related merge requests found
......@@ -107,7 +107,6 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
try {
$this->workspaceManager->setActiveWorkspace($this->entity);
$this->messenger->addMessage($this->t('%workspace_label is now the active workspace.', ['%workspace_label' => $this->entity->label()]));
$form_state->setRedirect('<front>');
}
catch (WorkspaceAccessException $e) {
$this->messenger->addError($this->t('You do not have access to activate the %workspace_label workspace.', ['%workspace_label' => $this->entity->label()]));
......
......@@ -208,7 +208,7 @@ protected function offCanvasRender(array &$build) {
$rows = array_slice($build['table']['#rows'], 0, 5, TRUE);
foreach ($rows as $id => $row) {
if ($active_workspace->id() !== $id) {
$url = Url::fromRoute('entity.workspace.activate_form', ['workspace' => $id]);
$url = Url::fromRoute('entity.workspace.activate_form', ['workspace' => $id], ['query' => $this->getDestinationArray()]);
$default_class = $id === WorkspaceInterface::DEFAULT_WORKSPACE ? 'workspaces__item--default' : 'workspaces__item--not-default';
$items[] = [
'#type' => 'link',
......
<?php
namespace Drupal\Tests\workspaces\FunctionalJavascript;
use Drupal\Tests\system\FunctionalJavascript\OffCanvasTestBase;
/**
* Tests workspace settings stray integration.
*
* @group workspaces
*/
class WorkspaceToolbarIntegrationTest extends OffCanvasTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['toolbar', 'workspaces'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$admin_user = $this->drupalCreateUser([
'administer workspaces',
'access toolbar',
'access administration pages',
]);
$this->drupalLogin($admin_user);
}
/**
* Test workspace canvas can be toggled with JavaScript.
*/
public function testWorkspaceCanvasToggling() {
$page = $this->getSession()->getPage();
$assert_session = $this->assertSession();
// Set size for horizontal toolbar.
$this->getSession()->resizeWindow(1200, 600);
$this->drupalGet('<front>');
// Wait for toolbar to appear.
$this->assertNotEmpty($assert_session->waitForElement('css', 'body.toolbar-horizontal'));
// Open workspace canvas.
$page->clickLink('Switch workspace');
$this->waitForOffCanvasToOpen('top');
$assert_session->elementExists('css', '.workspaces-dialog');
// Close Canvas.
$page->pressButton('Close');
$this->waitForOffCanvasToClose();
$assert_session->assertNoElementAfterWait('css', '.workspaces-dialog');
}
/**
* Test workspace switch and landing page behaviour.
*/
public function testWorkspaceSwitch() {
$page = $this->getSession()->getPage();
$assert_session = $this->assertSession();
// Wait for toolbar to appear.
$this->getSession()->resizeWindow(1200, 600);
$this->drupalGet('admin');
// Wait for toolbar to appear.
$this->assertNotEmpty($assert_session->waitForElement('css', 'body.toolbar-horizontal'));
// Open workspace canvas.
$page->clickLink('Switch workspace');
$this->waitForOffCanvasToOpen('top');
// Click 'stage' workspace and confirm switch.
$page->clickLink('Stage');
$this->assertElementVisibleAfterWait('css', '.workspace-activate-form.workspace-confirm-form');
$page->find('css', '.ui-dialog-buttonset .button--primary')->click();
$assert_session->waitForElementVisible('css', '.messages--status');
// Make sure we stay on same page after switch.
$assert_session->responseContains('<em class="placeholder">Stage</em> is now the active workspace.');
$assert_session->addressEquals('admin');
}
}
......@@ -152,7 +152,6 @@ function workspaces_cron() {
* Implements hook_toolbar().
*/
function workspaces_toolbar() {
$items = [];
$items['workspace'] = [
'#cache' => [
'contexts' => [
......@@ -160,7 +159,6 @@ function workspaces_toolbar() {
],
],
];
$current_user = \Drupal::currentUser();
if (!$current_user->hasPermission('administer workspaces')
&& !$current_user->hasPermission('view own workspace')
......@@ -176,7 +174,7 @@ function workspaces_toolbar() {
'tab' => [
'#type' => 'link',
'#title' => $active_workspace->label(),
'#url' => $active_workspace->toUrl('collection'),
'#url' => $active_workspace->toUrl('collection', ['query' => \Drupal::destination()->getAsArray()]),
'#attributes' => [
'title' => t('Switch workspace'),
'class' => ['use-ajax', 'toolbar-icon', 'toolbar-icon-workspace'],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment