You are here

public function EditUpdateForm::handleStates in Scheduled Publish 8.3

Handles state values, clean-up and ordering.

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

File

src/Form/EditUpdateForm.php, line 171
Contains \Drupal\scheduled_publish\Form\EditUpdateForm.

Class

EditUpdateForm

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