Skip to content
Snippets Groups Projects
Verified Commit e5c94094 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3165010 by dpi, acbramley, tim.plunkett, larowlan: Using the layout...

Issue #3165010 by dpi, acbramley, tim.plunkett, larowlan: Using the layout builder discard changes button should ignore any input and skip validation

(cherry picked from commit db43eba8)
parent 356da9c0
No related branches found
No related tags found
9 merge requests!4488Issue #3376281: Random machine names no longer need to be wrapped in strtolower(),!3149Issue #3282285: Email "" does not comply with addr-spec of RFC 2822,!3000Issue #793660: Check for failure of hook_install,!2940Issue #3320240: Entity count query returns a string instead of int,!2937Issue #3315245: Order of languages overrides default language fallback,!2877Issue #3056652 by yogeshmpawar, mashermike, aalin, ranjith_kumar_k_u: Link...,!1627Issue #3082958: Add gitignore(s) to composer-ready project templates,!1014Issue #3226806: Move filter implementations from filter.module to plugin classes,!939Issue #2971209: Allow the MediaLibraryUiBuilder service to use an alternative view display
......@@ -198,6 +198,8 @@ protected function actions(array $form, FormStateInterface $form_state) {
'#value' => $this->t('Discard changes'),
'#submit' => ['::redirectOnSubmit'],
'#redirect' => 'discard_changes',
// Discard is not dependent on form input.
'#limit_validation_errors' => [],
];
// @todo This button should be conditionally displayed, see
// https://www.drupal.org/node/2917777.
......
<?php
namespace Drupal\Tests\layout_builder\Functional;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Entity\Entity\EntityFormMode;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay;
use Drupal\Tests\BrowserTestBase;
/**
* Tests Layout Builder forms.
*
* @group layout_builder
*/
class LayoutBuilderFormModeTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'field',
'entity_test',
'layout_builder',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'classy';
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
// Set up a field with a validation constraint.
$field_storage = FieldStorageConfig::create([
'field_name' => 'foo',
'entity_type' => 'entity_test',
'type' => 'string',
]);
$field_storage->save();
FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'entity_test',
// Expecting required value.
'required' => TRUE,
])->save();
// Enable layout builder custom layouts.
LayoutBuilderEntityViewDisplay::create([
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'default',
'status' => TRUE,
])
->enable()
->enableLayoutBuilder()
->setOverridable()
->save();
// Add the form mode and show the field with a constraint.
EntityFormMode::create([
'id' => 'entity_test.layout_builder',
'targetEntityType' => 'entity_test',
])->save();
EntityFormDisplay::create([
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'layout_builder',
'status' => TRUE,
])
->setComponent('foo', [
'type' => 'string_textfield',
])
->save();
$this->drupalLogin($this->drupalCreateUser([
'view test entity',
'configure any layout',
'configure all entity_test entity_test layout overrides',
]));
EntityTest::create()->setName($this->randomMachineName())->save();
}
/**
* Tests that the 'Discard changes' button skips validation and ignores input.
*/
public function testDiscardValidation() {
$page = $this->getSession()->getPage();
$assert_session = $this->assertSession();
// When submitting the form normally, a validation error should be shown.
$this->drupalGet('entity_test/1/layout');
$assert_session->fieldExists('foo[0][value]');
$assert_session->elementAttributeContains('named', ['field', 'foo[0][value]'], 'required', 'required');
$page->pressButton('Save layout');
$assert_session->pageTextContains('foo field is required.');
// When Discarding changes, a validation error will not be shown.
// Reload the form for fresh state.
$this->drupalGet('entity_test/1/layout');
$page->pressButton('Discard changes');
$assert_session->pageTextNotContains('foo field is required.');
$assert_session->addressEquals('entity_test/1/layout/discard-changes');
// Submit the form to ensure no invalid form state retained.
$page->pressButton('Confirm');
$assert_session->pageTextContains('The changes to the layout have been discarded.');
}
}
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