diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index ccf0c94..035a35c 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -507,12 +507,11 @@ function comment_node_update_index(EntityInterface $node, $langcode) { if (!$node->hasField($field_name)) { continue; } - $field_definition = $node->getFieldDefinition($field_name); - $mode = $field_definition->getSetting('default_mode'); - $comments_per_page = $field_definition->getSetting('per_page'); if ($node->get($field_name)->status) { + $display_settings = entity_get_display($node->getEntityTypeId(), $node->bundle(), 'default') + ->getComponent($field_name); $comments = \Drupal::entityManager()->getStorage('comment') - ->loadThread($node, $field_name, $mode, $comments_per_page); + ->loadThread($node, $field_name, $display_settings['settings']['default_mode'], $display_settings['settings']['per_page']); if ($comments) { comment_prepare_thread($comments); $build[] = \Drupal::entityManager()->getViewBuilder('comment')->viewMultiple($comments); diff --git a/core/modules/comment/src/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php b/core/modules/comment/src/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php index 3346cc2..f632ebd 100644 --- a/core/modules/comment/src/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php +++ b/core/modules/comment/src/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php @@ -345,13 +345,12 @@ protected function buildLinks(FieldItemListInterface $items) { $field_name = $this->fieldDefinition->getName(); $entity = $items->getEntity(); $commenting_status = $items->status; - if ($commenting_status) { - $field_definition = $this->fieldDefinition; + if ($commenting_status != CommentItemInterface::HIDDEN) { + // Entity has commenting status open or closed. $link_style = $this->getSetting('show_links'); - // Node has commenting open or closed. if ($link_style == static::LINKS_RSS) { // Add a comments RSS element which is a URL to the comments of this - // node. + // entity. $options = array( 'fragment' => 'comments', 'absolute' => TRUE, @@ -363,7 +362,7 @@ protected function buildLinks(FieldItemListInterface $items) { } elseif ($link_style == static::LINKS_PAGE) { // Default links: display the number of comments that have been posted, - // or a link to add new comments if the user has permission, the node + // or a link to add new comments if the user has permission, the entity // is open to new comments, and there currently are none. if ($this->currentUser->hasPermission('access comments')) { if (!empty($items->comment_count)) { @@ -400,7 +399,7 @@ protected function buildLinks(FieldItemListInterface $items) { 'attributes' => array('title' => t('Add a new comment to this page.')), 'fragment' => 'comment-form', ); - if ($comment_form_location == COMMENT_FORM_SEPARATE_PAGE) { + if ($comment_form_location == CommentItemInterface::FORM_SEPARATE_PAGE) { $links['comment-add']['route_name'] = 'comment.reply'; $links['comment-add']['route_parameters'] = array( 'entity_type' => $entity->getEntityTypeId(), @@ -429,13 +428,13 @@ protected function buildLinks(FieldItemListInterface $items) { if ($this->currentUser->hasPermission('post comments')) { // Show the "post comment" link if the form is on another page, or // if there are existing comments that the link will skip past. - if ($comment_form_location == COMMENT_FORM_SEPARATE_PAGE || (!empty($items->comment_count) && $this->currentUser->hasPermission('access comments'))) { + if ($comment_form_location == CommentItemInterface::FORM_SEPARATE_PAGE || (!empty($items->comment_count) && $this->currentUser->hasPermission('access comments'))) { $links['comment-add'] = array( 'title' => t('Add new comment'), 'attributes' => array('title' => t('Share your thoughts and opinions related to this posting.')), 'fragment' => 'comment-form', ); - if ($comment_form_location == COMMENT_FORM_SEPARATE_PAGE) { + if ($comment_form_location == CommentItemInterface::FORM_SEPARATE_PAGE) { $links['comment-add']['route_name'] = 'comment.reply'; $links['comment-add']['route_parameters'] = array( 'entity_type' => $entity->getEntityTypeId(), diff --git a/core/modules/comment/src/Tests/CommentTestBase.php b/core/modules/comment/src/Tests/CommentTestBase.php index 5d044cf..7572317 100644 --- a/core/modules/comment/src/Tests/CommentTestBase.php +++ b/core/modules/comment/src/Tests/CommentTestBase.php @@ -280,7 +280,7 @@ public function setCommentPreview($mode, $field_name = 'comment') { * Defaults to 'comment'. */ public function setCommentForm($enabled, $field_name = 'comment') { - $this->setCommentFormatterSettings('form_location', ($enabled ? CommentItemInterface::FORM_BELOW : CommentItemInterface::COMMENT_FORM_SEPARATE_PAGE), 'Comment controls ' . ($enabled ? 'enabled' : 'disabled') . '.', $field_name); + $this->setCommentFormatterSettings('form_location', ($enabled ? CommentItemInterface::FORM_BELOW : CommentItemInterface::FORM_SEPARATE_PAGE), 'Comment controls ' . ($enabled ? 'enabled' : 'disabled') . '.', $field_name); } /** diff --git a/core/profiles/standard/standard.install b/core/profiles/standard/standard.install index 647a406..0e55bc4 100644 --- a/core/profiles/standard/standard.install +++ b/core/profiles/standard/standard.install @@ -4,6 +4,7 @@ * Install, update and uninstall functions for the standard installation profile. */ +use Drupal\comment\CommentManagerInterface; use Drupal\comment\Plugin\Field\FieldFormatter\CommentDefaultFormatter; use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; @@ -40,8 +41,8 @@ function standard_install() { 'weight' => 20, 'settings' => array( 'per_page' => 50, - 'default_mode' => COMMENT_MODE_THREADED, - 'form_location' => COMMENT_FORM_BELOW, + 'default_mode' => CommentManagerInterface::COMMENT_MODE_THREADED, + 'form_location' => CommentItemInterface::FORM_BELOW, 'show_links' => CommentDefaultFormatter::LINKS_TEASER, ), ))