Creates a comment entity.
$nid: Node id which will hold the comment.
$uid: User id of the author of the comment. Can be NULL if $contact provided.
$contact: Set to NULL for no contact info, TRUE to ignore success checking, and array of values to set contact info.
$pid: Comment id of the parent comment in a thread.
function saveComment($nid, $uid, $contact = NULL, $pid = 0) {
$values = array(
'nid' => $nid,
'uid' => $uid,
'pid' => $pid,
'node_type' => 'comment_node_article',
'subject' => $this
->randomName(),
'comment_body' => $this
->randomName(),
'status' => 1,
);
if ($contact) {
$values += $contact;
}
$comment = entity_create('comment', $values);
$comment
->save();
return $comment;
}