You are here

public function EditUpdateForm::submitForm in Scheduled Publish 8.3

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

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

Class

EditUpdateForm

Namespace

Drupal\scheduled_publish\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $state = $form_state
    ->getValue('moderation_state');
  $date = $form_state
    ->getValue('value');
  $date
    ->setTimezone(new \DateTimezone(ScheduledPublish::STORAGE_TIMEZONE));
  $value = $date
    ->format(ScheduledPublish::DATETIME_STORAGE_FORMAT);
  $entity = $form_state
    ->get([
    'scheduled_publish',
    'entity',
  ]);
  $field = $form_state
    ->get([
    'scheduled_publish',
    'field',
  ]);
  $delta = $form_state
    ->get([
    'scheduled_publish',
    'field_delta',
  ]);
  $states = $entity
    ->get($field)
    ->getValue();
  $states[$delta]['moderation_state'] = $state;
  $states[$delta]['value'] = $value;
  $this
    ->handleStates($form_state, $states);

  // Reload entity to be sure it's not old.
  $entity = \Drupal::entityTypeManager()
    ->getStorage($entity
    ->getEntityTypeId())
    ->load($entity
    ->id());
  $entity
    ->set($field, $states);
  $entity
    ->save();
  $this
    ->messenger()
    ->addStatus($this
    ->t('Status update changed.'));
}