You are here

public function HeartbeatRevisionDeleteForm::submitForm in Heartbeat 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/HeartbeatRevisionDeleteForm.php, line 106

Class

HeartbeatRevisionDeleteForm
Provides a form for deleting a Heartbeat revision.

Namespace

Drupal\heartbeat\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $this->HeartbeatStorage
    ->deleteRevision($this->revision
    ->getRevisionId());
  $this
    ->logger('content')
    ->notice('Heartbeat: deleted %title revision %revision.', array(
    '%title' => $this->revision
      ->label(),
    '%revision' => $this->revision
      ->getRevisionId(),
  ));
  drupal_set_message(t('Revision from %revision-date of Heartbeat %title has been deleted.', array(
    '%revision-date' => format_date($this->revision
      ->getRevisionCreationTime()),
    '%title' => $this->revision
      ->label(),
  )));
  $form_state
    ->setRedirect('entity.heartbeat.canonical', array(
    'heartbeat' => $this->revision
      ->id(),
  ));
  if ($this->connection
    ->query('SELECT COUNT(DISTINCT vid) FROM {heartbeat_field_revision} WHERE id = :id', array(
    ':id' => $this->revision
      ->id(),
  ))
    ->fetchField() > 1) {
    $form_state
      ->setRedirect('entity.heartbeat.version_history', array(
      'heartbeat' => $this->revision
        ->id(),
    ));
  }
}