function CommentController::commentApprove

Same name and namespace in other branches
  1. 8.9.x core/modules/comment/src/Controller/CommentController.php \Drupal\comment\Controller\CommentController::commentApprove()
  2. 10 core/modules/comment/src/Controller/CommentController.php \Drupal\comment\Controller\CommentController::commentApprove()
  3. 11.x core/modules/comment/src/Controller/CommentController.php \Drupal\comment\Controller\CommentController::commentApprove()

Publishes the specified comment.

Parameters

\Drupal\comment\CommentInterface $comment: A comment entity.

Return value

\Symfony\Component\HttpFoundation\RedirectResponse

1 string reference to 'CommentController::commentApprove'
comment.routing.yml in core/modules/comment/comment.routing.yml
core/modules/comment/comment.routing.yml

File

core/modules/comment/src/Controller/CommentController.php, line 102

Class

CommentController
Controller for the comment entity.

Namespace

Drupal\comment\Controller

Code

public function commentApprove(CommentInterface $comment) {
    $comment->setPublished();
    $comment->save();
    $this->messenger()
        ->addStatus($this->t('Comment approved.'));
    $permalink_uri = $comment->permalink();
    $permalink_uri->setAbsolute();
    return new RedirectResponse($permalink_uri->toString());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.