diff -u b/core/modules/comment/comment.module b/core/modules/comment/comment.module --- b/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -202,8 +202,6 @@ // Comment links are only added to node entity type for backwards // compatibility. Should you require comment links for other entity types you // can do so by implementing a new field formatter. - // @todo Make this configurable from the formatter see - // http://drupal.org/node/1901110 $links = \Drupal::service('comment.link_builder')->buildCommentedEntityLinks($node, $context); $node_links += $links; @@ -220,6 +218,8 @@ // Comment links are only added to node entity type for backwards // compatibility. Should you require comment links for other entity types you // can do so by implementing a new field formatter. + // @todo Make this configurable from the formatter see + // http://drupal.org/node/1901110 $links = \Drupal::service('comment.link_builder')->buildCommentedEntityLinks($node, $context); $node_links += $links; @@ -451,17 +451,18 @@ $build = array(); if ($index_comments) { + $node_base_defs = \Drupal::entityManager()->getFieldStorageDefinitions($node->getEntityTypeId()); foreach (\Drupal::service('comment.manager')->getFields('node') as $field_name => $info) { // Skip fields that entity does not have. 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) { + $comment_type = CommentType::load($node_base_defs[$field_name]->getSetting('comment_type')); + $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, $comment_type->getThreadingMode(), $display_settings['settings']['per_page']); if ($comments) { comment_prepare_thread($comments); $build[] = \Drupal::entityManager()->getViewBuilder('comment')->viewMultiple($comments); @@ -470,18 +471,17 @@ $build = array(); if ($index_comments) { - $node_base_defs = \Drupal::entityManager()->getFieldStorageDefinitions($node->getEntityTypeId()); foreach (\Drupal::service('comment.manager')->getFields('node') as $field_name => $info) { // Skip fields that entity does not have. 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) { - $comment_type = CommentType::load($node_base_defs[$field_name]->getSetting('comment_type')); - $display_settings = entity_get_display($node->getEntityTypeId(), $node->bundle(), 'default') - ->getComponent($field_name); $comments = \Drupal::entityManager()->getStorage('comment') - ->loadThread($node, $field_name, $comment_type->getThreadingMode(), $display_settings['settings']['per_page']); + ->loadThread($node, $field_name, $mode, $comments_per_page); if ($comments) { comment_prepare_thread($comments); $build[] = \Drupal::entityManager()->getViewBuilder('comment')->viewMultiple($comments); @@ -791,7 +791,7 @@ $element = $variables['element']; if ($element['#field_type'] == 'comment') { // Provide contextual information. - $variables['comment_display_mode'] = $element[0]['#comment_display_mode']; + $variables['comment_threading_mode'] = $element[0]['#comment_threading_mode']; $variables['comment_type'] = $element[0]['#comment_type']; // Append additional attributes (eg. RDFa) from the first field item. @@ -810,7 +810,7 @@ $element = $variables['element']; if ($element['#field_type'] == 'comment') { // Provide contextual information. - $variables['comment_threading_mode'] = $element[0]['#comment_threading_mode']; + $variables['comment_display_mode'] = $element[0]['#comment_display_mode']; $variables['comment_type'] = $element[0]['#comment_type']; // Adjust a comment field's attributes. diff -u b/core/modules/comment/config/schema/comment.schema.yml b/core/modules/comment/config/schema/comment.schema.yml --- b/core/modules/comment/config/schema/comment.schema.yml +++ b/core/modules/comment/config/schema/comment.schema.yml @@ -51,6 +51,9 @@ description: type: text label: 'Description' + threading_mode: + type: integer + label: 'Threading' field.storage_settings.comment: type: mapping @@ -59,9 +62,6 @@ description: type: text label: 'Description' - threading_mode: - type: integer - label: 'Threading' field.comment.storage_settings: type: sequence interdiff impossible; taking evasive action reverted: --- b/core/modules/comment/src/CommentForm.php +++ a/core/modules/comment/src/CommentForm.php @@ -384,23 +384,14 @@ else { drupal_set_message($this->t('Your comment has been posted.')); } + $query = array(); + // Find the current display page for this comment. + $field_definition = $this->entityManager->getFieldDefinitions($entity->getEntityTypeId(), $entity->bundle())[$field_name]; + $page = $this->entityManager->getStorage('comment')->getDisplayOrdinal($comment, $field_definition->getSetting('default_mode'), $field_definition->getSetting('per_page')); + if ($page > 0) { + $query['page'] = $page; - // Find the current display page for this comment. We link to it using - // the standard entity urlInfo, i.e. the full/default view mode. - $page_number = 0; - $display = $this->entityManager->getStorage('entity_view_display') - ->load($entity->getEntityTypeId() . '.' . $entity->bundle() . '.full'); - if (!$display) { - $display = $this->entityManager->getStorage('entity_view_display') - ->load($entity->getEntityTypeId() . '.' . $entity->bundle() . '.default'); - } - $formatter_options = $display ? $display->getComponent($field_name): NULL; - if ($formatter_options) { - $field_definition = $this->entityManager->getFieldStorageDefinitions($entity->getEntityTypeId())[$field_name]; - $comment_type = $this->entityManager->getStorage('comment_type')->load($field_definition->getSetting('comment_type')); - $page_number = $this->entityManager->getStorage('comment')->getDisplayOrdinal($comment, $comment_type->getThreadingMode(), $formatter_options['settings']['per_page']); } // Redirect to the newly posted comment. - $query = $page_number ? array('page' => $page_number) : NULL; $uri->setOption('query', $query); $uri->setOption('fragment', 'comment-' . $comment->id()); } unchanged: --- a/core/modules/comment/src/CommentForm.php +++ b/core/modules/comment/src/CommentForm.php @@ -367,14 +367,23 @@ public function save(array $form, FormStateInterface $form_state) { else { drupal_set_message($this->t('Your comment has been posted.')); } - $query = array(); - // Find the current display page for this comment. - $field_definition = $this->entityManager->getFieldDefinitions($entity->getEntityTypeId(), $entity->bundle())[$field_name]; - $page = $this->entityManager->getStorage('comment')->getDisplayOrdinal($comment, $field_definition->getSetting('default_mode'), $field_definition->getSetting('per_page')); - if ($page > 0) { - $query['page'] = $page; + // Find the current display page for this comment. We link to it using + // the standard entity urlInfo, i.e. the full/default view mode. + $page_number = 0; + $display = $this->entityManager->getStorage('entity_view_display') + ->load($entity->getEntityTypeId() . '.' . $entity->bundle() . '.full'); + if (!$display) { + $display = $this->entityManager->getStorage('entity_view_display') + ->load($entity->getEntityTypeId() . '.' . $entity->bundle() . '.default'); + } + $formatter_options = $display ? $display->getComponent($field_name): NULL; + if ($formatter_options) { + $field_definition = $this->entityManager->getFieldStorageDefinitions($entity->getEntityTypeId())[$field_name]; + $comment_type = $this->entityManager->getStorage('comment_type')->load($field_definition->getSetting('comment_type')); + $page_number = $this->entityManager->getStorage('comment')->getDisplayOrdinal($comment, $comment_type->getThreadingMode(), $formatter_options['settings']['per_page']); } // Redirect to the newly posted comment. + $query = $page_number ? array('page' => $page_number) : NULL; $uri->setOption('query', $query); $uri->setOption('fragment', 'comment-' . $comment->id()); }