You are here

public function SocialCommentController::commentUnpublish in Open Social 8.8

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_comment/src/Controller/SocialCommentController.php \Drupal\social_comment\Controller\SocialCommentController::commentUnpublish()
  2. 8.7 modules/social_features/social_comment/src/Controller/SocialCommentController.php \Drupal\social_comment\Controller\SocialCommentController::commentUnpublish()
  3. 10.3.x modules/social_features/social_comment/src/Controller/SocialCommentController.php \Drupal\social_comment\Controller\SocialCommentController::commentUnpublish()
  4. 10.0.x modules/social_features/social_comment/src/Controller/SocialCommentController.php \Drupal\social_comment\Controller\SocialCommentController::commentUnpublish()
  5. 10.1.x modules/social_features/social_comment/src/Controller/SocialCommentController.php \Drupal\social_comment\Controller\SocialCommentController::commentUnpublish()
  6. 10.2.x modules/social_features/social_comment/src/Controller/SocialCommentController.php \Drupal\social_comment\Controller\SocialCommentController::commentUnpublish()

Publishes the specified comment.

Parameters

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

Return value

\Symfony\Component\HttpFoundation\RedirectResponse Redirect to where.

Throws

\Drupal\Core\Entity\EntityStorageException

1 string reference to 'SocialCommentController::commentUnpublish'
social_comment.routing.yml in modules/social_features/social_comment/social_comment.routing.yml
modules/social_features/social_comment/social_comment.routing.yml

File

modules/social_features/social_comment/src/Controller/SocialCommentController.php, line 71

Class

SocialCommentController
Controller routine override to change relevant bits in the password reset.

Namespace

Drupal\social_comment\Controller

Code

public function commentUnpublish(CommentInterface $comment) {
  $comment
    ->setUnpublished();
  $comment
    ->save();
  $this
    ->messenger()
    ->addStatus($this
    ->t('Comment unpublished.'));
  if ($entity = $comment
    ->getCommentedEntity()) {

    // Check access permissions for the entity.

    /* @var \Drupal\Core\Entity\EntityBase $entity */
    if (!$entity
      ->access('view')) {
      throw new AccessDeniedHttpException();
    }

    /* @var \Drupal\Core\Url $url */
    if ($url = $entity
      ->urlInfo('canonical')) {

      // Redirect the user to the correct entity.
      return $this
        ->redirectToOriginalEntity($url, $comment, $entity);
    }
  }
  throw new AccessDeniedHttpException();
}