You are here

public function EntityModerationForm::submitForm in Workbench Moderation 8.2

Same name and namespace in other branches
  1. 8 src/Form/EntityModerationForm.php \Drupal\workbench_moderation\Form\EntityModerationForm::submitForm()

@inheritDoc

Overrides FormInterface::submitForm

File

src/Form/EntityModerationForm.php, line 117

Class

EntityModerationForm

Namespace

Drupal\workbench_moderation\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  /** @var ContentEntityInterface $entity */
  $entity = $form_state
    ->get('entity');
  $new_state = $form_state
    ->getValue('new_state');
  $entity->moderation_state->target_id = $new_state;
  $entity->revision_log = $form_state
    ->getValue('revision_log');
  $entity
    ->save();
  drupal_set_message($this
    ->t('The moderation state has been updated.'));

  /** @var ModerationState $state */
  $state = $this->entityTypeManager
    ->getStorage('moderation_state')
    ->load($new_state);

  // The page we're on likely won't be visible if we just set the entity to
  // the default state, as we hide that latest-revision tab if there is no
  // forward revision. Redirect to the canonical URL instead, since that will
  // still exist.
  if ($state
    ->isDefaultRevisionState()) {
    $form_state
      ->setRedirectUrl($entity
      ->toUrl('canonical'));
  }
}