diff --git a/core/modules/text/tests/src/FunctionalJavascript/TextIntegrationTest.php b/core/modules/text/tests/src/FunctionalJavascript/TextIntegrationTest.php new file mode 100644 index 0000000..d5c3b00 --- /dev/null +++ b/core/modules/text/tests/src/FunctionalJavascript/TextIntegrationTest.php @@ -0,0 +1,54 @@ +drupalCreateUser([ + 'access content', + 'administer site configuration', + 'access content overview', + ]); + $this->drupalLogin($admin_user); + + // Create a Content type and two test nodes. + $this->createContentType(['type' => 'page']); + + // Log in a user who can create 'page' nodes. + $user = $this->drupalCreateUser(['create page content']); + $this->drupalLogin($user); + + // Go to "Page" node creation page. + $this->drupalGet('node/add/page'); + + // Assert Edit summary link presence. + $this->assertSession()->responseContains(' ()'); + + // Add help text to Basic Page's Body field. + $edit['title[0][value]'] = $this->randomMachineName(8); + $edit['body[0][value]'] = $this->randomMachineName(16); + // Stay on the current page, without reloading. + $this->drupalPostForm(NULL, $edit, t('Save')); + + // Assert Edit summary link presence. + $this->assertSession()->responseContains(' ()'); + + } + +} diff --git a/core/modules/text/text.js b/core/modules/text/text.js index ad89bd8..86d2128 100644 --- a/core/modules/text/text.js +++ b/core/modules/text/text.js @@ -22,38 +22,42 @@ var $summary = $widget.find('.js-text-summary-wrapper'); var $summaryLabel = $summary.find('label').eq(0); - var $full = $widget.find('.js-text-full').closest('.js-form-item'); - var $fullLabel = $full.find('label').eq(0); + var $full = $widget.find('textarea.js-text-full').closest('.js-form-item'); - // Create a placeholder label when the field cardinality is greater - // than 1. - if ($fullLabel.length === 0) { - $fullLabel = $('').prependTo($full); - } + function setUpEditSummaryButton() { + var $fullLabel = $(this).find('label').eq(0); - // Set up the edit/hide summary link. - var $link = $(' ()'); - var $button = $link.find('button'); - var toggleClick = true; - $link.on('click', function (e) { - if (toggleClick) { - $summary.hide(); - $button.html(Drupal.t('Edit summary')); - $link.appendTo($fullLabel); - } - else { - $summary.show(); - $button.html(Drupal.t('Hide summary')); - $link.appendTo($summaryLabel); + // Create a placeholder label when the field cardinality is greater + // than 1. + if ($fullLabel.length === 0) { + $fullLabel = $('').prependTo($full); } - e.preventDefault(); - toggleClick = !toggleClick; - }).appendTo($summaryLabel); - // If no summary is set, hide the summary field. - if ($widget.find('.js-text-summary').val() === '') { - $link.trigger('click'); + // Set up the edit/hide summary link. + var $link = $(' ()'); + var $button = $link.find('button'); + var toggleClick = true; + $link.on('click', function (e) { + if (toggleClick) { + $summary.hide(); + $button.html(Drupal.t('Edit summary')); + $link.appendTo($fullLabel); + } + else { + $summary.show(); + $button.html(Drupal.t('Hide summary')); + $link.appendTo($summaryLabel); + } + e.preventDefault(); + toggleClick = !toggleClick; + }).appendTo($summaryLabel); + + // If no summary is set, hide the summary field. + if ($widget.find('.js-text-summary').val() === '') { + $link.trigger('click'); + } } + $full.each(setUpEditSummaryButton); }); } };