You are here

protected function CommentDeleteManager::keepReplies in Comment Delete 8

Soft delete comment and keep replies at current level.

Parameters

\Drupal\comment\Entity\Comment $comment: The comment entity.

1 call to CommentDeleteManager::keepReplies()
CommentDeleteManager::delete in src/CommentDeleteManager.php
Delete a comment and do something with its replies.

File

src/CommentDeleteManager.php, line 265

Class

CommentDeleteManager
Service container for comment delete operations.

Namespace

Drupal\comment_delete

Code

protected function keepReplies(Comment $comment) {

  // Get the total number of replies to the comment. If the comment has
  // no replies we can safely hard delete the comment.
  $replies_count = $this->commentStorage
    ->getQuery()
    ->condition('pid', $comment
    ->id())
    ->count()
    ->execute();
  if ($replies_count > 0) {

    // Replies exist so do the soft delete boogie.
    $this
      ->softDelete($comment);
  }
  else {
    if (!$this->config
      ->get('soft')) {
      try {
        $comment
          ->delete();
      } catch (EntityStorageException $e) {

        // Unable to delete.
        watchdog_exception('comment_delete', $e);
      }
    }
    else {
      $this
        ->softDelete($comment);
    }
  }
}