Issue #3010825 by mark_fullmer, tim.plunkett, tedbow, johndevman: Back to site link returns user to manage layout for defaults
parent
82bba2741a
commit
e1838d0272
|
@ -125,6 +125,11 @@ class LayoutBuilder extends RenderElement implements ContainerFactoryPluginInter
|
|||
}
|
||||
$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 @@ abstract class ConfigureBlockFormBase extends FormBase implements BaseFormIdInte
|
|||
$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 @@ class ConfigureSectionForm extends FormBase {
|
|||
$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 @@ class DiscardLayoutChangesForm extends ConfirmFormBase {
|
|||
*/
|
||||
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 @@ class LayoutBuilderDisableForm extends ConfirmFormBase {
|
|||
}
|
||||
|
||||
$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 @@ abstract class LayoutRebuildConfirmFormBase extends ConfirmFormBase {
|
|||
$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 @@ class RevertOverridesForm extends ConfirmFormBase {
|
|||
}
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
<?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");
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue