Builds the comment-related elements for node detail pages.
\Drupal\Core\Entity\EntityInterface $node: The node entity for which to build the comment-related elements.
A renderable array representing the comment-related page elements for the node.
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;
}