You are here

public static function CommentDeleteSubmitter::submitForm in Comment Delete 8

Submit handler for the comment delete form.

Parameters

array $form: The form.

\Drupal\Core\Form\FormStateInterface $form_state: The form state.

File

src/CommentDeleteSubmitter.php, line 23

Class

CommentDeleteSubmitter
Submit callback handler for deleting comment.

Namespace

Drupal\comment_delete

Code

public static function submitForm(array &$form, FormStateInterface $form_state) {

  /** @var \Drupal\comment_delete\CommentDeleteManager $comment_delete_manager */
  $comment_delete_manager = \Drupal::service('comment_delete.manager');

  /** @var \Drupal\comment\Form\DeleteForm $form_object */
  $form_object = $form_state
    ->getFormObject();

  /** @var \Drupal\comment\Entity\Comment $comment */
  $comment = $form_object
    ->getEntity();
  $comment_delete_manager
    ->delete($comment, $form_state
    ->getValue('delete_operation'));
  if ($comment_delete_manager
    ->isAjaxRequest()) {

    // No redirect on Ajax request. Presumably the module or custom
    // integration adding Ajax support to comments handles the Ajax response.
    $form_state
      ->disableRedirect();
  }
  else {
    $entity_type = $comment
      ->getCommentedEntityTypeId();
    $form_state
      ->setRedirect("entity.{$entity_type}.canonical", [
      $entity_type => $comment
        ->getCommentedEntityId(),
    ]);
  }
}