You are here

public function ReferenceRevisionDeleteForm::submitForm in Bibliography & Citation 2.0.x

Same name and namespace in other branches
  1. 8 modules/bibcite_entity/src/Form/ReferenceRevisionDeleteForm.php \Drupal\bibcite_entity\Form\ReferenceRevisionDeleteForm::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

modules/bibcite_entity/src/Form/ReferenceRevisionDeleteForm.php, line 121

Class

ReferenceRevisionDeleteForm
Provides a form for reverting a reference revision.

Namespace

Drupal\bibcite_entity\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $this->referenceStorage
    ->deleteRevision($this->revision
    ->getRevisionId());
  $this
    ->logger('bibcite')
    ->notice('@type: deleted %title revision %revision.', [
    '@type' => $this->revision
      ->bundle(),
    '%title' => $this->revision
      ->label(),
    '%revision' => $this->revision
      ->getRevisionId(),
  ]);
  $type = ReferenceType::load($this->revision
    ->bundle());
  $type_label = $type ? $type
    ->label() : $this->revision
    ->bundle();
  $this
    ->messenger()
    ->addStatus($this
    ->t('Revision from %revision-date of @type %title has been deleted.', [
    '%revision-date' => $this->dateFormatter
      ->format($this->revision
      ->getRevisionCreationTime()),
    '@type' => $type_label,
    '%title' => $this->revision
      ->label(),
  ]));
  $form_state
    ->setRedirect('entity.bibcite_reference.canonical', [
    'bibcite_reference' => $this->revision
      ->id(),
  ]);
  $query = $this->connection
    ->select('bibcite_reference_revision', 'br');
  $query
    ->addExpression('COUNT(DISTINCT(revision_id))');
  $query
    ->condition('id', $this->revision
    ->id());
  $count = $query
    ->execute()
    ->fetchField();
  if ($count > 1) {
    $form_state
      ->setRedirect('entity.bibcite_reference.version_history', [
      'bibcite_reference' => $this->revision
        ->id(),
    ]);
  }
}