diff --git a/core/modules/comment/comment-entity-form.js b/core/modules/comment/comment-entity-form.js deleted file mode 100644 index fd16d8b..0000000 --- a/core/modules/comment/comment-entity-form.js +++ /dev/null @@ -1,23 +0,0 @@ -/** - * @file - * Attaches comment behaviors to the entity form. - */ - -(function ($, Drupal) { - - 'use strict'; - - /** - * - * @type {Drupal~behavior} - */ - Drupal.behaviors.commentFieldsetSummaries = { - attach: function (context) { - var $context = $(context); - $context.find('fieldset.comment-entity-settings-form').drupalSetSummary(function (context) { - return Drupal.checkPlain($(context).find('.js-form-item-comment input:checked').next('label').text()); - }); - } - }; - -})(jQuery, Drupal); diff --git a/core/modules/comment/comment.libraries.yml b/core/modules/comment/comment.libraries.yml index 78c4ff0..cff9f2e 100644 --- a/core/modules/comment/comment.libraries.yml +++ b/core/modules/comment/comment.libraries.yml @@ -1,7 +1,7 @@ drupal.comment: version: VERSION js: - comment-entity-form.js: {} + js/comment-entity-form.js: {} dependencies: - core/jquery - core/drupal diff --git a/core/modules/comment/js/comment-entity-form.js b/core/modules/comment/js/comment-entity-form.js new file mode 100644 index 0000000..93b222f --- /dev/null +++ b/core/modules/comment/js/comment-entity-form.js @@ -0,0 +1,22 @@ +/** + * @file + * Attaches comment behaviors to the entity form. + */ + +(function ($, Drupal) { + + 'use strict'; + + /** + * @type {Drupal~behavior} + */ + Drupal.behaviors.commentFieldsetSummaries = { + attach: function (context) { + var $context = $(context); + $context.find('[data-drupal-selector="edit-comment-0"]').drupalSetSummary(function (context) { + return $context.find('[data-drupal-selector="edit-comment-0-status"] input:checked').next('label').text(); + }); + } + }; + +})(jQuery, Drupal); diff --git a/core/modules/comment/src/Plugin/Field/FieldWidget/CommentWidget.php b/core/modules/comment/src/Plugin/Field/FieldWidget/CommentWidget.php index 818226d..56c44bb 100644 --- a/core/modules/comment/src/Plugin/Field/FieldWidget/CommentWidget.php +++ b/core/modules/comment/src/Plugin/Field/FieldWidget/CommentWidget.php @@ -71,9 +71,6 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen // default values for the field. '#open' => ($items->status != $field_default_values[0]['status']), '#group' => 'advanced', - '#attributes' => array( - 'class' => array('comment-' . Html::getClass($entity->getEntityTypeId()) . '-settings-form'), - ), '#attached' => array( 'library' => array('comment/drupal.comment'), ), diff --git a/core/modules/comment/tests/src/FunctionalJavascript/EntitySettingsFormTest.php b/core/modules/comment/tests/src/FunctionalJavascript/EntitySettingsFormTest.php new file mode 100644 index 0000000..d01271c --- /dev/null +++ b/core/modules/comment/tests/src/FunctionalJavascript/EntitySettingsFormTest.php @@ -0,0 +1,63 @@ +createContentType(array('type' => 'article', 'name' => t('Article'))); + $this->addDefaultCommentField('node', 'article'); + } + + /** + * Tests if the vertical tab summary can be updated with JavaScript. + */ + public function testVerticalTabsSummary() { + + $web_user = $this->drupalCreateUser([ + 'administer content types', + 'administer comments', + ]); + $this->drupalLogin($web_user); + + $this->drupalGet('node/add/article'); + $this->assertSummary(t('Open')); + $this->click('[data-drupal-selector="edit-comment-0-status-1"]'); + $this->assertSummary(t('Closed')); + $this->click('[data-drupal-selector="edit-comment-0-status-2"]'); + $this->assertSummary(t('Open')); + } + + /** + * Asserts that corresponding vertical tab has a correct summary. + * + * @param string $summary + * Summary value to check. + */ + protected function assertSummary($summary) { + $condition = sprintf('jQuery(".is-selected .vertical-tabs__menu-item-summary").text() == "%s"', $summary); + $this->assertJsCondition($condition); + } + +}