diff --git a/core/modules/outside_in/src/Block/BlockEntityOffCanvasForm.php b/core/modules/outside_in/src/Block/BlockEntityOffCanvasForm.php index 0b813eaca1..0504a2cbe2 100644 --- a/core/modules/outside_in/src/Block/BlockEntityOffCanvasForm.php +++ b/core/modules/outside_in/src/Block/BlockEntityOffCanvasForm.php @@ -154,6 +154,9 @@ public function buildForm(array $form, FormStateInterface $form_state) { * @return \Drupal\Core\Ajax\AjaxResponse * An AJAX response that display validation error messages or redirects * to a URL + * + * @todo Repalce this callback with generic trait in + * https://www.drupal.org/node/2896535. */ public function submitFormDialog(array &$form, FormStateInterface $form_state) { $response = new AjaxResponse(); @@ -186,10 +189,8 @@ protected function getRedirectUrl() { // \Drupal\Core\Routing\RedirectDestination::get() cannot be used directly // because it will use if 'destination' is not in the query // string. - if ($this->getRequest()->get('destination')) { - if ($destination = $this->getRedirectDestination()->get()) { - return Url::fromUserInput('/' . $destination); - } + if ($this->getRequest()->query->has('destination') && $destination = $this->getRedirectDestination()->get()) { + return Url::fromUserInput('/' . $destination); } } diff --git a/core/modules/outside_in/tests/modules/outside_in_test/outside_in_test.module b/core/modules/outside_in/tests/modules/outside_in_test/outside_in_test.module deleted file mode 100644 index 5410cfb535..0000000000 --- a/core/modules/outside_in/tests/modules/outside_in_test/outside_in_test.module +++ /dev/null @@ -1,30 +0,0 @@ -getValue(['settings', 'label']) == 'Block label') { - $form_state->setError($element, 'Meta label error.'); - } -} diff --git a/core/modules/outside_in/tests/modules/outside_in_test/src/Plugin/Block/ValidationErrorBlock.php b/core/modules/outside_in/tests/modules/outside_in_test/src/Plugin/Block/ValidationErrorBlock.php new file mode 100644 index 0000000000..095e2799e9 --- /dev/null +++ b/core/modules/outside_in/tests/modules/outside_in_test/src/Plugin/Block/ValidationErrorBlock.php @@ -0,0 +1,33 @@ + "\u{2600} \u{27A1} \u{1F415} \u{1F6B6} \u{1F570}"]; + } + + /** + * {@inheritdoc} + */ + public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { + parent::validateConfigurationForm($form, $form_state); + $form_state->setError($form['label'], "\u{1F525} Sorry system error. Please save again. \u{1F61C}"); + } + +} diff --git a/core/modules/outside_in/tests/src/FunctionalJavascript/OutsideInBlockFormTest.php b/core/modules/outside_in/tests/src/FunctionalJavascript/OutsideInBlockFormTest.php index 131e27b937..5c7a791533 100644 --- a/core/modules/outside_in/tests/src/FunctionalJavascript/OutsideInBlockFormTest.php +++ b/core/modules/outside_in/tests/src/FunctionalJavascript/OutsideInBlockFormTest.php @@ -511,23 +511,16 @@ public function testValidationMessages() { $web_assert = $this->assertSession(); foreach ($this->getTestThemes() as $theme) { $this->enableTheme($theme); - $block = $this->placeBlock('system_powered_by_block'); + $block = $this->placeBlock('outside_in_test_validation'); $this->drupalGet('user'); $this->enableEditMode(); $this->openBlockForm($this->getBlockSelector($block)); - - // Confirm "Display Title" is not checked. - $web_assert->checkboxNotChecked('settings[label_display]'); - // Confirm Title is not visible. - $this->assertEquals($this->isLabelInputVisible(), FALSE, 'Label is not visible'); - $page->checkField('settings[label_display]'); - $this->assertEquals($this->isLabelInputVisible(), TRUE, 'Label is visible'); // Use label that will trigger validation error. // @see _outside_in_test_validate_title $page->fillField('settings[label]', 'Block label'); - $page->pressButton('Save Powered by Drupal'); + $page->pressButton('Save Block with validation error'); $web_assert->assertWaitOnAjaxRequest(); - $web_assert->elementContains('css', '#drupal-off-canvas', 'Meta label error'); + $web_assert->elementContains('css', '#drupal-off-canvas', 'Sorry system error. Please save again'); $this->disableEditMode(); $block->delete(); }