diff --git a/core/modules/comment/comment-entity-form.js b/core/modules/comment/comment-entity-form.js index fd16d8b..be2acc3 100644 --- a/core/modules/comment/comment-entity-form.js +++ b/core/modules/comment/comment-entity-form.js @@ -14,8 +14,13 @@ 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()); + $context.find('.js-comment-settings-form').drupalSetSummary(function (context) { + var widgetSelector = $(context).data('comment-widget-selector'); + return $context + .find('[data-drupal-selector="' + widgetSelector + '"]') + .find('input:checked') + .next('label') + .text(); }); } }; diff --git a/core/modules/comment/src/Plugin/Field/FieldWidget/CommentWidget.php b/core/modules/comment/src/Plugin/Field/FieldWidget/CommentWidget.php index c9478f6..911881c 100644 --- a/core/modules/comment/src/Plugin/Field/FieldWidget/CommentWidget.php +++ b/core/modules/comment/src/Plugin/Field/FieldWidget/CommentWidget.php @@ -65,6 +65,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen // Override widget title to be helpful for end users. $element['#title'] = $this->t('Comment settings'); + $comment_widget_selector = 'edit-' . $this->fieldDefinition->getName() . '-' . $delta . '-status'; $element += [ '#type' => 'details', // Open the details when the selected value is different to the stored @@ -72,8 +73,13 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen '#open' => ($items->status != $field_default_values[0]['status']), '#group' => 'advanced', '#attributes' => [ - 'class' => ['comment-' . Html::getClass($entity->getEntityTypeId()) . '-settings-form'], - ], + 'class' => [ + 'js-comment-settings-form', + ], + 'data-field-name' => HTML::cleanCssIdentifier($this->fieldDefinition->getName()), + 'data-delta' => $delta, + 'data-comment-widget-selector' => HTML::cleanCssIdentifier($comment_widget_selector), + ], '#attached' => [ 'library' => ['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..c91a789 --- /dev/null +++ b/core/modules/comment/tests/src/FunctionalJavascript/EntitySettingsFormTest.php @@ -0,0 +1,67 @@ +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); + } + +}