function comment_approve

Page callback: Publishes the specified comment.

Parameters

\Drupal\comment\Plugin\Core\Entity\Comment $comment: A comment entity.

See also

comment_menu()

1 string reference to 'comment_approve'
comment_menu in drupal/core/modules/comment/comment.module
Implements hook_menu().

File

drupal/core/modules/comment/comment.pages.inc, line 110
User page callbacks for the Comment module.

Code

function comment_approve(Comment $comment) {

  // @todo CSRF tokens are validated in page callbacks rather than access
  //   callbacks, because access callbacks are also invoked during menu link
  //   generation. Add token support to routing: http://drupal.org/node/755584.
  $token = drupal_container()
    ->get('request')->query
    ->get('token');
  if (!isset($token) || !drupal_valid_token($token, 'comment/' . $comment
    ->id() . '/approve')) {
    throw new AccessDeniedHttpException();
  }
  $comment->status->value = COMMENT_PUBLISHED;
  $comment
    ->save();
  drupal_set_message(t('Comment approved.'));
  drupal_goto('node/' . $comment->nid->target_id);
}