Issue #3037113 by tim.plunkett, andrewmacpherson: Replace layout builder discard-changes + revert-to-default links with buttons
parent
094890e633
commit
c04b1cef27
|
@ -98,14 +98,21 @@ class DefaultsEntityForm extends EntityForm {
|
|||
$actions['#weight'] = -1000;
|
||||
|
||||
$actions['discard_changes'] = [
|
||||
'#type' => 'link',
|
||||
'#title' => $this->t('Discard changes'),
|
||||
'#attributes' => ['class' => ['button']],
|
||||
'#url' => $this->sectionStorage->getLayoutBuilderUrl('discard_changes'),
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Discard changes'),
|
||||
'#submit' => ['::redirectOnSubmit'],
|
||||
'#redirect' => 'discard_changes',
|
||||
];
|
||||
return $actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form submission handler.
|
||||
*/
|
||||
public function redirectOnSubmit(array $form, FormStateInterface $form_state) {
|
||||
$form_state->setRedirectUrl($this->sectionStorage->getLayoutBuilderUrl($form_state->getTriggeringElement()['#redirect']));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
@ -132,22 +132,29 @@ class OverridesEntityForm extends ContentEntityForm {
|
|||
$actions['#weight'] = -1000;
|
||||
|
||||
$actions['discard_changes'] = [
|
||||
'#type' => 'link',
|
||||
'#title' => $this->t('Discard changes'),
|
||||
'#attributes' => ['class' => ['button']],
|
||||
'#url' => $this->sectionStorage->getLayoutBuilderUrl('discard_changes'),
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Discard changes'),
|
||||
'#submit' => ['::redirectOnSubmit'],
|
||||
'#redirect' => 'discard_changes',
|
||||
];
|
||||
// @todo This link should be conditionally displayed, see
|
||||
// @todo This button should be conditionally displayed, see
|
||||
// https://www.drupal.org/node/2917777.
|
||||
$actions['revert'] = [
|
||||
'#type' => 'link',
|
||||
'#title' => $this->t('Revert to defaults'),
|
||||
'#attributes' => ['class' => ['button']],
|
||||
'#url' => $this->sectionStorage->getLayoutBuilderUrl('revert'),
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Revert to defaults'),
|
||||
'#submit' => ['::redirectOnSubmit'],
|
||||
'#redirect' => 'revert',
|
||||
];
|
||||
return $actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form submission handler.
|
||||
*/
|
||||
public function redirectOnSubmit(array $form, FormStateInterface $form_state) {
|
||||
$form_state->setRedirectUrl($this->sectionStorage->getLayoutBuilderUrl($form_state->getTriggeringElement()['#redirect']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the section storage object.
|
||||
*
|
||||
|
|
|
@ -295,8 +295,7 @@ class LayoutBuilderTest extends BrowserTestBase {
|
|||
$assert_session->elementExists('css', '.field--name-nid');
|
||||
$assert_session->pageTextContains('ID');
|
||||
$assert_session->pageTextContains('1');
|
||||
$assert_session->linkExists('Revert to defaults');
|
||||
$this->clickLink('Revert to defaults');
|
||||
$page->pressButton('Revert to defaults');
|
||||
$page->pressButton('Revert');
|
||||
$assert_session->addressEquals('node/1');
|
||||
$assert_session->pageTextContains('The layout has been reverted back to defaults.');
|
||||
|
@ -386,7 +385,7 @@ class LayoutBuilderTest extends BrowserTestBase {
|
|||
$this->clickLink('Manage layout');
|
||||
// Confirm the body field only is shown once.
|
||||
$assert_session->elementsCount('css', '.field--name-body', 1);
|
||||
$this->clickLink('Discard changes');
|
||||
$page->pressButton('Discard changes');
|
||||
$page->pressButton('Confirm');
|
||||
|
||||
$this->clickLink('Teaser');
|
||||
|
@ -402,7 +401,7 @@ class LayoutBuilderTest extends BrowserTestBase {
|
|||
$assert_session->elementsCount('css', '.field--name-body', 1);
|
||||
|
||||
// Enable a disabled view mode.
|
||||
$page->clickLink('Discard changes');
|
||||
$page->pressButton('Discard changes');
|
||||
$page->pressButton('Confirm');
|
||||
$assert_session->addressEquals("$field_ui_prefix/display/teaser");
|
||||
$page->clickLink('Default');
|
||||
|
@ -531,7 +530,7 @@ class LayoutBuilderTest extends BrowserTestBase {
|
|||
$assert_session->pageTextContains('This is the default view mode');
|
||||
$this->drupalGet('node/1/layout');
|
||||
$assert_session->pageTextContains('This is the default view mode');
|
||||
$this->clickLink('Discard changes');
|
||||
$page->pressButton('Discard changes');
|
||||
$page->pressButton('Confirm');
|
||||
|
||||
// Enable the full view mode and customize it.
|
||||
|
@ -551,7 +550,7 @@ class LayoutBuilderTest extends BrowserTestBase {
|
|||
$assert_session->pageTextContains('This is the full view mode');
|
||||
$this->drupalGet('node/1/layout');
|
||||
$assert_session->pageTextContains('This is the full view mode');
|
||||
$this->clickLink('Discard changes');
|
||||
$page->pressButton('Discard changes');
|
||||
$page->pressButton('Confirm');
|
||||
|
||||
// Disable the full view mode, the default should be used again.
|
||||
|
@ -560,7 +559,7 @@ class LayoutBuilderTest extends BrowserTestBase {
|
|||
$assert_session->pageTextContains('This is the default view mode');
|
||||
$this->drupalGet('node/1/layout');
|
||||
$assert_session->pageTextContains('This is the default view mode');
|
||||
$this->clickLink('Discard changes');
|
||||
$page->pressButton('Discard changes');
|
||||
$page->pressButton('Confirm');
|
||||
}
|
||||
|
||||
|
@ -958,7 +957,7 @@ class LayoutBuilderTest extends BrowserTestBase {
|
|||
$assert_session->elementsCount('css', '.layout-builder__add-section', 2);
|
||||
|
||||
// Revert the override.
|
||||
$page->clickLink('Revert to defaults');
|
||||
$page->pressButton('Revert to defaults');
|
||||
$page->pressButton('Revert');
|
||||
$assert_session->elementsCount('css', '.layout', 0);
|
||||
$assert_session->pageTextNotContains('The first node body');
|
||||
|
|
|
@ -100,8 +100,7 @@ class InlineBlockTest extends InlineBlockTestBase {
|
|||
*
|
||||
* @dataProvider layoutNoSaveProvider
|
||||
*/
|
||||
public function testNoLayoutSave($operation, $no_save_link_text, $confirm_button_text) {
|
||||
|
||||
public function testNoLayoutSave($operation, $no_save_button_text, $confirm_button_text) {
|
||||
$this->drupalLogin($this->drupalCreateUser([
|
||||
'access contextual links',
|
||||
'configure any layout',
|
||||
|
@ -119,7 +118,7 @@ class InlineBlockTest extends InlineBlockTestBase {
|
|||
|
||||
$this->drupalGet('node/1/layout');
|
||||
$this->addInlineBlockToLayout('Block title', 'The block body');
|
||||
$this->clickLink($no_save_link_text);
|
||||
$page->pressButton($no_save_button_text);
|
||||
if ($confirm_button_text) {
|
||||
$page->pressButton($confirm_button_text);
|
||||
}
|
||||
|
@ -143,7 +142,7 @@ class InlineBlockTest extends InlineBlockTestBase {
|
|||
$this->drupalGet('node/1/layout');
|
||||
$this->configureInlineBlock('The block body', 'The block updated body');
|
||||
|
||||
$this->clickLink($no_save_link_text);
|
||||
$page->pressButton($no_save_button_text);
|
||||
if ($confirm_button_text) {
|
||||
$page->pressButton($confirm_button_text);
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ class LayoutBuilderUiTest extends WebDriverTestBase {
|
|||
|
||||
// Make and then discard changes.
|
||||
$this->assertModifiedLayout(static::FIELD_UI_PREFIX . '/display/default/layout');
|
||||
$page->clickLink('Discard changes');
|
||||
$page->pressButton('Discard changes');
|
||||
$page->pressButton('Confirm');
|
||||
$assert_session->pageTextNotContains('You have unsaved changes.');
|
||||
|
||||
|
|
Loading…
Reference in New Issue