1 comment.module comment_node_page_additions(Node $node)

Builds the comment-related elements for node detail pages.

Parameters

Node $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.

File

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

Code

function comment_node_page_additions(Node $node) {
  $node_type = node_type_get_type($node->type);

  $additions = array(
    'comments' => array(),
    'comment_form' => 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 ((!empty($node->comment_count) && user_access('access comments')) || user_access('administer comments')) {
    $mode = $node_type->settings['comment_mode'];
    $comments_per_page = $node_type->settings['comment_per_page'];
    if ($cids = comment_get_thread($node, $mode, $comments_per_page)) {
      $comments = comment_load_multiple($cids);
      comment_prepare_thread($comments);
      $build = comment_view_multiple($comments, $node);
      $build['pager']['#theme'] = 'pager';
      $additions['comments'] = $build;
    }
  }

  // Append comment form if needed.
  if (Comment::createAccess() && $node->comment == COMMENT_NODE_OPEN && ($node_type->settings['comment_form_location'] == COMMENT_FORM_BELOW)) {
    $comment = entity_create('comment', array('nid' => $node->nid));
    $additions['comment_form'] = backdrop_get_form("comment_node_{$node->type}_form", $comment);
  }

  return $additions;
}