function comment_publish_action

Publishes a comment.

Parameters

Drupal\comment\Comment $comment: (optional) A comment object to publish.

array $context: Array with components:

  • 'cid': Comment ID. Required if $comment is not given.

Related topics

1 call to comment_publish_action()
CommentActionsTest::testCommentPublishUnpublishActions in drupal/core/modules/comment/lib/Drupal/comment/Tests/CommentActionsTest.php
Tests comment publish and unpublish actions.

File

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

Code

function comment_publish_action(Comment $comment = NULL, $context = array()) {
  if (isset($comment->subject)) {
    $subject = $comment->subject;
    $comment->status = COMMENT_PUBLISHED;
  }
  else {
    $cid = $context['cid'];
    $subject = db_query('SELECT subject FROM {comment} WHERE cid = :cid', array(
      ':cid' => $cid,
    ))
      ->fetchField();
    db_update('comment')
      ->fields(array(
      'status' => COMMENT_PUBLISHED,
    ))
      ->condition('cid', $cid)
      ->execute();
  }
  watchdog('action', 'Published comment %subject.', array(
    '%subject' => $subject,
  ));
}