diff -u b/modules/webform_ajax/tests/src/FunctionalJavascript/WebformAjaxTest.php b/modules/webform_ajax/tests/src/FunctionalJavascript/WebformAjaxTest.php --- b/modules/webform_ajax/tests/src/FunctionalJavascript/WebformAjaxTest.php +++ b/modules/webform_ajax/tests/src/FunctionalJavascript/WebformAjaxTest.php @@ -10,7 +10,6 @@ * * @group webform_ajax * - * @todo Test the back link. * @todo This lumps a number of different tests together. AJAX is quite a cross- * cutting concern and I'd welcome input on how best to slice up the tests. */ @@ -30,9 +29,8 @@ $webform = $this->provider->webformWithTextfield(); $webform->setSetting('confirmation_type', 'message'); $webform->save(); - $path = $webform->toUrl()->getInternalPath(); $assert = $this->assertSession(); - $this->drupalPostForm($path, ['textfield' => 'test value'], t('Submit')); + $this->drupalPostForm($webform->toUrl(), ['textfield' => 'test value'], t('Submit')); $element = $assert->waitForElement('css', '.messages--status'); $this->assertNotNull($element, "An AJAX submission shows a confirmation message."); @@ -49,7 +47,6 @@ $webform = $this->provider->webformWithTextfield(); $webform->setSetting('confirmation_type', 'inline'); $webform->save(); - $path = $webform->toUrl()->getInternalPath(); // @todo Use an API call to get the form ID. $form_id = 'webform_submission_' . $webform->id() . '_form'; // The inline confirmation message is wrapped in the same wrapper the form @@ -58,7 +55,7 @@ $locator = "#webform-ajax-$form_id .webform-confirmation"; $assert = $this->assertSession(); - $this->drupalPostForm($path, ['textfield' => 'test value'], t('Submit')); + $this->drupalPostForm($webform->toUrl()->getInternalPath(), ['textfield' => 'test value'], t('Submit')); $element = $assert->waitForElement('css', $locator); $this->assertNotNull($element, "An AJAX submission shows an inline confirmation message."); @@ -73,10 +70,9 @@ $webform = $this->provider->webformWithTextfield(); $webform->setSetting('confirmation_type', 'message'); $webform->save(); - $path = $webform->toUrl()->getInternalPath(); $assert = $this->assertSession(); - $this->drupalPostForm($path, ['textfield' => 'test value'], t('Submit')); + $this->drupalPostForm($webform->toUrl(), ['textfield' => 'test value'], t('Submit')); $assert->waitForElement('css', '.messages--status'); $this->drupalPostForm(NULL, ['textfield' => 'test value 2'], t('Submit')); // I'm not sure there's an element I can wait on. @@ -97,10 +93,9 @@ $webform = $this->provider->webformWithTextfield(); $webform->setSetting('confirmation_type', 'message'); $webform->save(); - $path = $webform->toUrl()->getInternalPath(); $assert = $this->assertSession(); - $this->drupalPostForm($path, ['textfield' => 'test value'], t('Submit')); + $this->drupalPostForm($webform->toUrl(), ['textfield' => 'test value'], t('Submit')); $assert->waitForElement('css', '.messages--status'); /** @var \Drupal\webform\WebformSubmissionStorageInterface $storage */ $storage = \Drupal::entityTypeManager()->getStorage('webform_submission'); @@ -117,10 +112,9 @@ $webform = $this->provider->webformWithTextfield(['#required' => TRUE]); $webform->setSetting('confirmation_type', 'message'); $webform->save(); - $path = $webform->toUrl()->getInternalPath(); $assert = $this->assertSession(); - $this->drupalPostForm($path, ['textfield' => ''], t('Submit')); + $this->drupalPostForm($webform->toUrl(), ['textfield' => ''], t('Submit')); $element = $assert->waitForElement('css', '.messages--error'); $this->assertNotNull($element, "An AJAX submission triggers server-side validation errors."); @@ -134,10 +128,9 @@ $webform = $this->provider->webformWithTextfield(); $webform->setSetting('confirmation_type', 'message'); $webform->save(); - $path = $webform->toUrl()->getInternalPath(); $assert = $this->assertSession(); - $this->drupalPostForm($path, ['textfield' => 'test value'], t('Submit')); + $this->drupalPostForm($webform->toUrl(), ['textfield' => 'test value'], t('Submit')); $assert->waitForElement('css', '.messages--warning'); $this->drupalPostForm(NULL, ['textfield' => 'test value 2'], t('Submit')); $assert->assertWaitOnAjaxRequest(); @@ -154,10 +147,9 @@ $webform = $this->provider->multipageWebformWithTextfields(); $webform->setSetting('confirmation_type', 'message'); $webform->save(); - $path = $webform->toUrl()->getInternalPath(); $assert = $this->assertSession(); - $this->drupalPostForm($path, ['textfield_1' => 'test value page 1'], t('Next Page >')); + $this->drupalPostForm($webform->toUrl(), ['textfield_1' => 'test value page 1'], t('Next Page >')); $element = $assert->waitForButton('Submit'); $this->assertNotNull($element, "An AJAX submission on the first page of a multi-page form causes the next page to show"); @@ -174,16 +166,17 @@ /** * Test the back link. + * + * @todo: Incorpate this into another test. */ public function testBackLink() { // For now use the test_element_text webform as an easy check. $webform = $this->provider->webformWithTextfield(); $webform->setSetting('confirmation_type', 'inline'); $webform->save(); - $path = $webform->toUrl()->getInternalPath(); $assert = $this->assertSession(); - $this->drupalPostForm($path, ['textfield' => 'test value'], t('Submit')); + $this->drupalPostForm($webform->toUrl(), ['textfield' => 'test value'], t('Submit')); $back_link = $assert->waitForLink('Back to form'); $this->assertNotNull($back_link, "An AJAX submission confirmation shows a 'Back to form' link."); diff -u b/modules/webform_ajax/webform_ajax.module b/modules/webform_ajax/webform_ajax.module --- b/modules/webform_ajax/webform_ajax.module +++ b/modules/webform_ajax/webform_ajax.module @@ -51,7 +51,7 @@ // AJAX submissions only make sense with certain kinds of confirmation. // @todo Disable the AJAX setting in the UI based on the confirmation type. $confirmation_type = $webform->getSetting('confirmation_type'); - if (!in_array($confirmation_type, ['message', 'inline'])) { + if (!in_array($confirmation_type, ['message', 'inline'], TRUE)) { return; } @@ -84,24 +84,21 @@ $response = new AjaxResponse(); $output = []; - $confirmation_type = $webform->getSetting('confirmation_type'); - if ($submission->getState() == WebformSubmissionInterface::STATE_COMPLETED) { - switch ($confirmation_type) { - case 'message': - // Currently the message set by webform itself is being squashed by - // \Drupal\webform\WebformMessageManager::display() with an explicit - // AJAX check.. - // @todo: Neaten this up - _webform_display_confirmation_message($submission); - $output = _webform_ajax_get_fresh_submission_form($webform); - break; - - case 'inline': - $confirmation = webform_ajax_confirmation_message($submission, $element_id); - // Add the same wrapper as the form (messages go above it, and it gets - // replaced when clicking the back link). - $output = _webform_ajax_wrap_element($confirmation, $element_id); - break; + if ($submission->getState() == WebformSubmissionInterface::STATE_COMPLETED) { + $confirmation_type = $webform->getSetting('confirmation_type'); + if ($confirmation_type === 'message') { + // Currently the message set by webform itself is being squashed by + // \Drupal\webform\WebformMessageManager::display() with an explicit + // AJAX check.. + // @todo: Neaten this up + _webform_display_confirmation_message($submission); + $output = _webform_ajax_get_fresh_submission_form($webform); + } + elseif ($confirmation_type === 'inline') { + $confirmation = webform_ajax_confirmation_message($submission, $element_id); + // Add the same wrapper as the form (messages go above it, and it gets + // replaced when clicking the back link). + $output = _webform_ajax_wrap_element($confirmation, $element_id); } } else { @@ -166,7 +163,6 @@ */ function webform_ajax_confirmation_message(WebformSubmissionInterface $submission, $element_id) { $webform = $submission->getWebform(); - /** @var \Drupal\webform\WebformMessageManagerInterface $message_manager */ $source_entity = $submission->getSourceEntity(); $url = Url::fromRoute('webform_ajax.return_webform', [ 'webform' => $webform->id(), reverted: --- b/webform.info.yml +++ a/webform.info.yml @@ -8,5 +8,3 @@ - 'drupal:field' - 'drupal:system (>= 8.2)' - 'drupal:user' -test_dependencies: - - webform_ajax