You are here

public function AnonymousPublishingClAdminModeration::submitForm in Anonymous Publishing 8

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

modules/anonymous_publishing_cl/src/Form/AnonymousPublishingClAdminModeration.php, line 211

Class

AnonymousPublishingClAdminModeration
This class defines the moderation setting form for this module, available at : admin/config/people/anonymous_publishing_cl/moderation

Namespace

Drupal\anonymous_publishing_cl\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $operation = $form_state
    ->getValue('operation');
  $ids = $form_state
    ->getValue('items');
  $hidden = unserialize($form_state
    ->getValue('hidden_values'));
  foreach ($ids as $id) {

    // Load the entity depending on type:
    $entity = NULL;
    switch ($hidden[$id]) {
      case 'node':
        $entity = Node::load($id);
        break;
      case 'comment':
        $entity = Comment::load($id);
        break;
    }
    if ($entity) {
      if ($operation == 'unpublish') {
        $entity
          ->setPublished(FALSE);
        $entity
          ->save();
      }
      elseif ($operation == 'publish') {
        $entity
          ->setPublished(TRUE);
        $entity
          ->save();
      }
    }
  }
  $this
    ->messenger()
    ->addMessage($this
    ->t('The update has been performed.'));
}