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..b6fefc8 --- /dev/null +++ b/core/modules/text/tests/src/FunctionalJavascript/TextIntegrationTest.php @@ -0,0 +1,59 @@ +drupalCreateUser([ + 'access text', + 'administer site configuration', + 'access content overview', + ]); + $this->drupalLogin($admin_user); + + // Create basic Page. + $title = $this->randomMachineName(8); + $node = array( + 'title' => $title, + 'body' => array(array('value' => $this->randomMachineName(32))), + 'uid' => $this->webUser->id(), + 'type' => 'article', + ); + /** @var \Drupal\node\NodeInterface $node */ + $node = Node::create($node); + $this->clickLink(t('Edit')); + + // Assert Edit summary link presence. + $this->assertRaw(' ()', 'Edit Summary link found.'); + + // Add help text to Basic Page's Body field. + $title_key = 'title[0][value]'; + $body_key = 'body[0][value]'; + $edit = array(); + $edit[$title_key] = $this->randomMachineName(8); + $edit[$body_key] = $this->randomMachineName(16); + // Stay on the current page, without reloading. + $this->drupalPostForm(NULL, $edit, t('Save')); + + // Assert Edit summary link presence. + $this->assertRaw(' ()', 'Edit Summary link found.'); + + } + +} 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); }); } };