You are here

public function CommentDeleteManager::delete in Comment Delete 8

Delete a comment and do something with its replies.

Parameters

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

int $op: The operation type.

File

src/CommentDeleteManager.php, line 153

Class

CommentDeleteManager
Service container for comment delete operations.

Namespace

Drupal\comment_delete

Code

public function delete(Comment $comment, $op = self::KEEP_REPLIES) {
  switch ($op) {
    case self::DELETE_REPLIES:

      // Delete comment and replies. Default Drupal behavior.
      $this
        ->deleteReplies($comment);
      break;
    case self::MOVE_REPLIES:

      // Delete comment and move replies up one thread.
      $this
        ->moveReplies($comment);
      break;
    case self::KEEP_REPLIES:

      // Soft delete comment and keep replies at current thread.
      $this
        ->keepReplies($comment);
      break;
  }

  // Set translatable confirmation message.
  $this->messenger
    ->addMessage($this->config
    ->get('message'));
}