You are here

public function ConfigEntityRevisionsDeleteFormBase::submitForm in Config Entity Revisions 8.2

Same name and namespace in other branches
  1. 8 src/ConfigEntityRevisionsDeleteFormBase.php \Drupal\config_entity_revisions\ConfigEntityRevisionsDeleteFormBase::submitForm()
  2. 1.x src/ConfigEntityRevisionsDeleteFormBase.php \Drupal\config_entity_revisions\ConfigEntityRevisionsDeleteFormBase::submitForm()

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/ConfigEntityRevisionsDeleteFormBase.php, line 189

Class

ConfigEntityRevisionsDeleteFormBase
Provides a form for reverting a config entity revision.

Namespace

Drupal\config_entity_revisions

Code

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

  // Someone else may have deleted a revision so we can't assume the state
  // when the form was rendered is still valid.
  $revisions = $this->controller
    ->getRevisionIds($this->config_entity
    ->getContentEntityId());
  if (count($revisions) == 1) {
    \Drupal::messenger()
      ->addMessage(t('There is only one revision remaining. You may not delete it, sorry.'), 'error');
  }
  else {

    // Ensure content moderation won't throw errors.
    $this->config_entity
      ->contentEntityStorage()
      ->resetDefaultRevision($this->revision, $this->revision->revision->value);
    if ($this->config_entity
      ->hasOwnContent()) {
      $this->config_entity
        ->deleteRelatedContentEntities($this->revision->revision->value);
    }
    $this->controller
      ->deleteRevision($this->revision);
    $this
      ->logUpdate();
    $this
      ->displayUpdate();
  }
  if (count($revisions) > 2) {
    $this
      ->setRevisionsFormRedirect($form_state);
  }
  else {
    $this
      ->setBuildFormRedirect($form_state);
  }
}