You are here

function comment_node_page_additions in Drupal 7

Build the comment-related elements for node detail pages.

Parameters

$node: A node object.

1 call to comment_node_page_additions()
comment_node_view in modules/comment/comment.module
Implements hook_node_view().

File

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

Code

function comment_node_page_additions($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, $node);
      $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) {
    $build = drupal_get_form("comment_node_{$node->type}_form", (object) array(
      'nid' => $node->nid,
    ));
    $additions['comment_form'] = $build;
  }
  if ($additions) {
    $additions += array(
      '#theme' => 'comment_wrapper__node_' . $node->type,
      '#node' => $node,
      'comments' => array(),
      'comment_form' => array(),
    );
  }
  return $additions;
}