You are here

public function SitewideAlertRevisionDeleteForm::submitForm in Sitewide Alert 8

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/SitewideAlertRevisionDeleteForm.php, line 118

Class

SitewideAlertRevisionDeleteForm
Provides a form for deleting a Sitewide Alert revision.

Namespace

Drupal\sitewide_alert\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $this->SitewideAlertStorage
    ->deleteRevision($this->revision
    ->getRevisionId());
  $this
    ->logger('content')
    ->notice('Sitewide Alert: deleted %title revision %revision.', [
    '%title' => $this->revision
      ->label(),
    '%revision' => $this->revision
      ->getRevisionId(),
  ]);
  $this
    ->messenger()
    ->addMessage(t('Revision from %revision-date of Sitewide Alert %title has been deleted.', [
    '%revision-date' => $this->dateFormatter
      ->format($this->revision
      ->getRevisionCreationTime()),
    '%title' => $this->revision
      ->label(),
  ]));
  $form_state
    ->setRedirect('entity.sitewide_alert.canonical', [
    'sitewide_alert' => $this->revision
      ->id(),
  ]);
  if ($this->connection
    ->query('SELECT COUNT(DISTINCT vid) FROM {sitewide_alert_field_revision} WHERE id = :id', [
    ':id' => $this->revision
      ->id(),
  ])
    ->fetchField() > 1) {
    $form_state
      ->setRedirect('entity.sitewide_alert.version_history', [
      'sitewide_alert' => $this->revision
        ->id(),
    ]);
  }
}