示例#1
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $operation = $form_state->getValue('operation');
     $cids = $form_state->getValue('comments');
     foreach ($cids as $cid) {
         // Delete operation handled in \Drupal\comment\Form\ConfirmDeleteMultiple
         // see \Drupal\comment\Controller\AdminController::adminPage().
         if ($operation == 'unpublish') {
             $comment = $this->commentStorage->load($cid);
             $comment->setPublished(FALSE);
             $comment->save();
         } elseif ($operation == 'publish') {
             $comment = $this->commentStorage->load($cid);
             $comment->setPublished(TRUE);
             $comment->save();
         }
     }
     drupal_set_message($this->t('The update has been performed.'));
     $form_state->setRedirect('comment.admin');
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, array &$form_state)
 {
     $operation = $form_state['values']['operation'];
     $cids = $form_state['values']['comments'];
     foreach ($cids as $cid) {
         // Delete operation handled in \Drupal\comment\Form\ConfirmDeleteMultiple
         // see \Drupal\comment\Controller\AdminController::adminPage().
         if ($operation == 'unpublish') {
             $comment = $this->commentStorage->load($cid);
             $comment->setPublished(FALSE);
             $comment->save();
         } elseif ($operation == 'publish') {
             $comment = $this->commentStorage->load($cid);
             $comment->setPublished(TRUE);
             $comment->save();
         }
     }
     drupal_set_message($this->t('The update has been performed.'));
     $form_state['redirect_route'] = array('route_name' => 'comment.admin');
 }