You are here

public function DataPolicyRevisionRevertForm::submitForm in Data Policy 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/DataPolicyRevisionRevertForm.php, line 124

Class

DataPolicyRevisionRevertForm
Provides a form for reverting a Data policy revision.

Namespace

Drupal\data_policy\Form

Code

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

  // The revision timestamp will be updated when the revision is saved. Keep
  // the original one for the confirmation message.
  $original_revision_timestamp = $this->revision
    ->getRevisionCreationTime();
  $this->revision = $this
    ->prepareRevertedRevision($this->revision, $form_state);
  $this->revision->revision_log = $this
    ->t('Copy of the revision from %date.', [
    '%date' => $this->dateFormatter
      ->format($original_revision_timestamp),
  ]);
  $this->revision
    ->save();
  $this
    ->logger('content')
    ->notice('Data policy: reverted revision %revision.', [
    '%revision' => $this->revision
      ->getRevisionId(),
  ]);
  $this
    ->messenger()
    ->addStatus($this
    ->t('Data policy has been reverted to the revision from %revision-date.', [
    '%revision-date' => $this->dateFormatter
      ->format($original_revision_timestamp),
  ]));
  $form_state
    ->setRedirectUrl($this
    ->getCancelUrl());
}