function comment_node_page_additions

Builds the comment-related elements for node detail pages.

Parameters

\Drupal\Core\Entity\EntityInterface $node: The node entity for which to build the comment-related elements.

Return value

A renderable array representing the comment-related page elements for the node.

2 calls to comment_node_page_additions()
comment_node_view in drupal/core/modules/comment/comment.module
Implements hook_node_view().
node_row_node_view_preprocess_node in drupal/core/modules/node/node.views.inc
Implements hook_preprocess_node().

File

drupal/core/modules/comment/comment.module, line 682
Enables users to comment on published content.

Code

function comment_node_page_additions(EntityInterface $node) {
  $additions = array();

  // Only attempt to render comments if the node has visible comments.
  // Unpublished comments are not included in $node->comment_count, so show
  // comments unconditionally if the user is an administrator.
  if ($node->comment_count && user_access('access comments') || user_access('administer comments')) {
    $mode = variable_get('comment_default_mode_' . $node->type, COMMENT_MODE_THREADED);
    $comments_per_page = variable_get('comment_default_per_page_' . $node->type, 50);
    if ($cids = comment_get_thread($node, $mode, $comments_per_page)) {
      $comments = comment_load_multiple($cids);
      comment_prepare_thread($comments);
      $build = comment_view_multiple($comments);
      $build['pager']['#theme'] = 'pager';
      $additions['comments'] = $build;
    }
  }

  // Append comment form if needed.
  if (user_access('post comments') && $node->comment == COMMENT_NODE_OPEN && variable_get('comment_form_location_' . $node->type, COMMENT_FORM_BELOW) == COMMENT_FORM_BELOW) {
    $additions['comment_form'] = comment_add($node);
  }
  if ($additions) {
    $additions += array(
      '#theme' => 'comment_wrapper__node_' . $node->type,
      '#node' => $node,
      'comments' => array(),
      'comment_form' => array(),
    );
  }
  return $additions;
}