You are here

public function CommentAdminOverview::submitForm in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/comment/src/Form/CommentAdminOverview.php \Drupal\comment\Form\CommentAdminOverview::submitForm()
  2. 9 core/modules/comment/src/Form/CommentAdminOverview.php \Drupal\comment\Form\CommentAdminOverview::submitForm()

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

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

Overrides FormInterface::submitForm

File

core/modules/comment/src/Form/CommentAdminOverview.php, line 268

Class

CommentAdminOverview
Provides the comments overview administration form.

Namespace

Drupal\comment\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $operation = $form_state
    ->getValue('operation');
  $cids = $form_state
    ->getValue('comments');

  /** @var \Drupal\comment\CommentInterface[] $comments */
  $comments = $this->commentStorage
    ->loadMultiple($cids);
  if ($operation != 'delete') {
    foreach ($comments as $comment) {
      if ($operation == 'unpublish') {
        $comment
          ->setUnpublished();
      }
      elseif ($operation == 'publish') {
        $comment
          ->setPublished();
      }
      $comment
        ->save();
    }
    $this
      ->messenger()
      ->addStatus($this
      ->t('The update has been performed.'));
    $form_state
      ->setRedirect('comment.admin');
  }
  else {
    $info = [];

    /** @var \Drupal\comment\CommentInterface $comment */
    foreach ($comments as $comment) {
      $langcode = $comment
        ->language()
        ->getId();
      $info[$comment
        ->id()][$langcode] = $langcode;
    }
    $this->tempStoreFactory
      ->get('entity_delete_multiple_confirm')
      ->set($this
      ->currentUser()
      ->id() . ':comment', $info);
    $form_state
      ->setRedirect('entity.comment.delete_multiple_form');
  }
}