You are here

public function DeleteUpdateForm::handleStates in Scheduled Publish 8.3

Handles state values, clean-up and ordering.

1 call to DeleteUpdateForm::handleStates()
DeleteUpdateForm::submitForm in src/Form/DeleteUpdateForm.php
Form submission handler.

File

src/Form/DeleteUpdateForm.php, line 164
Contains \Drupal\scheduled_publish\Form\DeleteUpdateForm.

Class

DeleteUpdateForm

Namespace

Drupal\scheduled_publish\Form

Code

public function handleStates(FormStateInterface $form_state, &$states) {
  $entity = $form_state
    ->get([
    'scheduled_publish',
    'entity',
  ]);
  $orig_status = $entity->moderation_state->value;
  $m_options = $this
    ->getModerationOptions($entity);

  // Make sure states are ordered correctly.
  $this
    ->handleStateOrdering($states);
  foreach ($states as $key => $state) {
    if (isset($m_options[$state['moderation_state']])) {
      $entity->moderation_state->value = $state['moderation_state'];
      $m_options = $this
        ->getModerationOptions($entity);
    }
    else {

      // Delete invalid state changes.
      unset($states[$key]);
    }
  }
  $entity->moderation_state->value = $orig_status;

  // Adjust ordering in case any invalid entries got removed.
  $this
    ->handleStateOrdering($states);
}