function CommentAdminOverview::submitForm

Same name in other branches
  1. 9 core/modules/comment/src/Form/CommentAdminOverview.php \Drupal\comment\Form\CommentAdminOverview::submitForm()
  2. 8.9.x core/modules/comment/src/Form/CommentAdminOverview.php \Drupal\comment\Form\CommentAdminOverview::submitForm()
  3. 11.x core/modules/comment/src/Form/CommentAdminOverview.php \Drupal\comment\Form\CommentAdminOverview::submitForm()

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');
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.