Page callback: Publishes the specified comment.
\Drupal\comment\Plugin\Core\Entity\Comment $comment: A comment entity.
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);
}