diff --git a/core/modules/outside_in/css/outside_in.module.css b/core/modules/outside_in/css/outside_in.module.css index 9d90bf227d..a0bb4a32aa 100644 --- a/core/modules/outside_in/css/outside_in.module.css +++ b/core/modules/outside_in/css/outside_in.module.css @@ -22,6 +22,11 @@ pointer-events: inherit; } +.ui-dialog-off-canvas .messages__wrapper:empty { + padding: 0; + margin: 0; +} + /* * Force the tray to be 100% width at the same breakpoint the dialog system uses * to expand dialog widths. diff --git a/core/modules/outside_in/src/OffCanvasFormDialogTrait.php b/core/modules/outside_in/src/OffCanvasFormDialogTrait.php index 36be157122..e29e8bb6b2 100644 --- a/core/modules/outside_in/src/OffCanvasFormDialogTrait.php +++ b/core/modules/outside_in/src/OffCanvasFormDialogTrait.php @@ -92,31 +92,25 @@ protected function buildFormDialog(array &$form, FormStateInterface $form_state) * to a URL */ public function submitFormDialog(array &$form, FormStateInterface $form_state) { + $response = new AjaxResponse(); if ($form_state->hasAnyErrors()) { unset($form['#prefix'], $form['#suffix']); $form['status_messages'] = [ '#type' => 'status_messages', '#weight' => -1000, ]; - $response = new AjaxResponse(); $response->addCommand(new HtmlCommand('#off-canvas-form', $form)); - // @todo Do we need the scroll to the top command from Webform? - //$response->addCommand(new ScrollTopCommand('#off-canvas-form')); - return $response; } else { - $response = new AjaxResponse(); - if ($path = $this->getRedirectDestinationPath()) { - $response->addCommand(new RedirectCommand('/' . $path)); - } - elseif ($redirect_url = $this->getRedirectUrl()) { - $response->addCommand(new RedirectCommand($redirect_url->toString())); + if ($redirect_url = $this->getRedirectUrl()) { + $response->addCommand(new RedirectCommand($redirect_url->setAbsolute() + ->toString())); } else { - $response->addCommand(new CloseDialogCommand()); + $response->addCommand(new CloseDialogCommand('#drupal-off-canvas')); } - return $response; } + return $response; } /** diff --git a/core/modules/outside_in/tests/modules/off_canvas_test/src/Controller/TestController.php b/core/modules/outside_in/tests/modules/off_canvas_test/src/Controller/TestController.php index 58bebc3a0b..1208edf2a0 100644 --- a/core/modules/outside_in/tests/modules/off_canvas_test/src/Controller/TestController.php +++ b/core/modules/outside_in/tests/modules/off_canvas_test/src/Controller/TestController.php @@ -111,6 +111,23 @@ public function linksDisplay() { ], ], ], + 'off_canvas_form_no_dest' => [ + '#title' => 'Show form: no destination!', + '#type' => 'link', + '#url' => Url::fromRoute( + 'off_canvas_test.form' + ), + '#attributes' => [ + 'class' => ['use-ajax'], + 'data-dialog-type' => 'dialog', + 'data-dialog-renderer' => 'off_canvas', + ], + '#attached' => [ + 'library' => [ + 'outside_in/drupal.outside_in', + ], + ], + ], ]; } diff --git a/core/modules/outside_in/tests/src/FunctionalJavascript/OffCanvasTest.php b/core/modules/outside_in/tests/src/FunctionalJavascript/OffCanvasTest.php index 23991a7073..12b979dbc5 100644 --- a/core/modules/outside_in/tests/src/FunctionalJavascript/OffCanvasTest.php +++ b/core/modules/outside_in/tests/src/FunctionalJavascript/OffCanvasTest.php @@ -127,17 +127,17 @@ public function testFormErrors() { $web_assert = $this->assertSession(); $page = $this->getSession()->getPage(); - // First submit form with no error. + // Submit form with no error and sending a destination. $this->drupalGet('/off-canvas-test-links'); $page->clickLink('Show form!'); $this->waitForOffCanvasToOpen(); $page->pressButton('Submit'); $web_assert->assertWaitOnAjaxRequest(); // Make sure the changes are present. - $web_assert->waitForElement('css', 'div.messages.messages--status:contains(submitted)'); + $this->assertNotEmpty($web_assert->waitForElement('css', 'div.messages.messages--status:contains(submitted)')); $web_assert->elementNotContains('css', 'body', 'Validation error'); - // Then submit form with error. + // Submit form with an error and sending a destination. $this->drupalGet('/off-canvas-test-links'); $page->clickLink('Show form!'); $this->waitForOffCanvasToOpen(); @@ -146,6 +146,31 @@ public function testFormErrors() { $web_assert->assertWaitOnAjaxRequest(); $web_assert->elementNotContains('css', 'body', 'submitted'); $web_assert->elementContains('css', '#drupal-off-canvas', 'Validation error'); + + // Submit form with no error and NOT sending a destination. + $this->drupalGet('/off-canvas-test-links'); + $page->clickLink('Show form: no destination!'); + $this->waitForOffCanvasToOpen(); + $page->pressButton('Submit'); + $web_assert->assertWaitOnAjaxRequest(); + // Make sure the changes are present. + $this->assertEmpty($web_assert->waitForElement('css', 'div.messages.messages--status:contains(submitted)')); + $web_assert->elementNotContains('css', 'body', 'Validation error'); + // If no validation error and no destination provided page will not be + // redirected but the dialog should be closed. + $this->waitForNoElement('css', '#drupal-off-canvas'); + + $this->drupalGet('/off-canvas-test-links'); + + // Submit form with error and NOT sending a destination. + $this->drupalGet('/off-canvas-test-links'); + $page->clickLink('Show form: no destination!'); + $this->waitForOffCanvasToOpen(); + $page->checkField('Force error?'); + $page->pressButton('Submit'); + $web_assert->assertWaitOnAjaxRequest(); + $web_assert->elementNotContains('css', 'body', 'submitted'); + $web_assert->elementContains('css', '#drupal-off-canvas', 'Validation error'); } }