function comment_add

Returns a rendered form to comment the given node.

Parameters

\Drupal\Core\Entity\EntityInterface $node: The node entity to be commented.

int $pid: (optional) Some comments are replies to other comments. In those cases, $pid is the parent comment's comment ID. Defaults to NULL.

Return value

array The renderable array for the comment addition form.

2 calls to comment_add()
comment_node_page_additions in drupal/core/modules/comment/comment.module
Builds the comment-related elements for node detail pages.
comment_reply in drupal/core/modules/comment/comment.pages.inc
Form constructor for the comment reply form.

File

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

Code

function comment_add(EntityInterface $node, $pid = NULL) {
  $values = array(
    'nid' => $node->nid,
    'pid' => $pid,
    'node_type' => 'comment_node_' . $node->type,
  );
  $comment = entity_create('comment', $values);
  return entity_get_form($comment);
}