Commit e1838d02 authored by alexpott's avatar alexpott

Issue #3010825 by mark_fullmer, tim.plunkett, tedbow, johndevman: Back to site...

Issue #3010825 by mark_fullmer, tim.plunkett, tedbow, johndevman: Back to site link returns user to manage layout for defaults
parent 82bba274
......@@ -125,6 +125,11 @@ protected function layout(SectionStorageInterface $section_storage) {
}
$output[] = $this->buildAddSectionLink($section_storage, $count);
$output['#attached']['library'][] = 'layout_builder/drupal.layout_builder';
// As the Layout Builder UI is typically displayed using the frontend theme,
// it is not marked as an administrative page at the route level even though
// it performs an administrative task. Mark this as an administrative page
// for JavaScript.
$output['#attached']['drupalSettings']['path']['currentPathIsAdmin'] = TRUE;
$output['#type'] = 'container';
$output['#attributes']['id'] = 'layout-builder';
$output['#attributes']['class'][] = 'layout-builder';
......
......@@ -192,6 +192,8 @@ public function doBuildForm(array $form, FormStateInterface $form_state, Section
$form['#id'] = Html::getId($form_state->getBuildInfo()['form_id']);
}
// Mark this as an administrative page for JavaScript ("Back to site" link).
$form['#attached']['drupalSettings']['path']['currentPathIsAdmin'] = TRUE;
return $form;
}
......
......@@ -133,6 +133,8 @@ public function buildForm(array $form, FormStateInterface $form_state, SectionSt
$target_highlight_id = $this->isUpdate ? $this->sectionUpdateHighlightId($delta) : $this->sectionAddHighlightId($delta);
$form['#attributes']['data-layout-builder-target-highlight-id'] = $target_highlight_id;
// Mark this as an administrative page for JavaScript ("Back to site" link).
$form['#attached']['drupalSettings']['path']['currentPathIsAdmin'] = TRUE;
return $form;
}
......
......@@ -87,6 +87,8 @@ public function getCancelUrl() {
*/
public function buildForm(array $form, FormStateInterface $form_state, SectionStorageInterface $section_storage = NULL) {
$this->sectionStorage = $section_storage;
// Mark this as an administrative page for JavaScript ("Back to site" link).
$form['#attached']['drupalSettings']['path']['currentPathIsAdmin'] = TRUE;
return parent::buildForm($form, $form_state);
}
......
......@@ -92,6 +92,8 @@ public function buildForm(array $form, FormStateInterface $form_state, SectionSt
}
$this->sectionStorage = $section_storage;
// Mark this as an administrative page for JavaScript ("Back to site" link).
$form['#attached']['drupalSettings']['path']['currentPathIsAdmin'] = TRUE;
return parent::buildForm($form, $form_state);
}
......
......@@ -86,6 +86,8 @@ public function buildForm(array $form, FormStateInterface $form_state, SectionSt
$form['#attributes']['data-layout-builder-target-highlight-id'] = $target_highlight_id;
}
// Mark this as an administrative page for JavaScript ("Back to site" link).
$form['#attached']['drupalSettings']['path']['currentPathIsAdmin'] = TRUE;
return $form;
}
......
......@@ -99,6 +99,8 @@ public function buildForm(array $form, FormStateInterface $form_state, SectionSt
}
$this->sectionStorage = $section_storage;
// Mark this as an administrative page for JavaScript ("Back to site" link).
$form['#attached']['drupalSettings']['path']['currentPathIsAdmin'] = TRUE;
return parent::buildForm($form, $form_state);
}
......
<?php
namespace Drupal\Tests\layout_builder\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
/**
* Test Layout Builder integration with Toolbar.
*
* @group layout_builder
*/
class LayoutBuilderToolbarTest extends WebDriverTestBase {
/**
* {@inheritdoc}
*/
public static $modules = [
'block',
'node',
'layout_builder',
'node',
'toolbar',
];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->drupalPlaceBlock('local_tasks_block');
// Create a content type.
$this->createContentType([
'type' => 'bundle_with_section_field',
'name' => 'Bundle with section field',
]);
$this->createNode([
'type' => 'bundle_with_section_field',
'title' => 'The first node title',
'body' => [
[
'value' => 'The first node body',
],
],
]);
}
/**
* Tests the 'Back to site' link behaves with manage layout as admin page.
*/
public function testBackToSiteLink() {
$assert_session = $this->assertSession();
$page = $this->getSession()->getPage();
$this->drupalLogin($this->drupalCreateUser([
'configure any layout',
'access administration pages',
'administer node display',
'administer node fields',
'access toolbar',
]));
$field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
// From the manage display page, go to manage the layout.
$this->drupalGet("$field_ui_prefix/display/default");
$this->drupalPostForm(NULL, ['layout[enabled]' => TRUE], 'Save');
$assert_session->linkExists('Manage layout');
$this->clickLink('Manage layout');
// Save the defaults.
$page->pressButton('Save layout');
$assert_session->addressEquals("$field_ui_prefix/display/default");
// As the Layout Builder UI is typically displayed using the frontend theme,
// it is not marked as an administrative page at the route level even though
// it performs an administrative task, therefore, we need to verify that it
// behaves as such, redirecting out of the admin section.
// Clicking "Back to site" navigates to the homepage.
$this->drupalGet("$field_ui_prefix/display/default/layout");
$this->clickLink('Back to site');
$assert_session->addressEquals("/user/2");
$this->drupalGet("$field_ui_prefix/display/default/layout/discard-changes");
$page->pressButton('Confirm');
$this->clickLink('Back to site');
$assert_session->addressEquals("/user/2");
$this->drupalGet("$field_ui_prefix/display/default/layout/disable");
$page->pressButton('Confirm');
$this->clickLink('Back to site');
$assert_session->addressEquals("/user/2");
}
}
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