You are here

public function ConsentAgreementRevisionRevertForm::submitForm in General Data Protection Regulation 8.2

Same name and namespace in other branches
  1. 8 modules/gdpr_consent/src/Form/ConsentAgreementRevisionRevertForm.php \Drupal\gdpr_consent\Form\ConsentAgreementRevisionRevertForm::submitForm()
  2. 3.0.x modules/gdpr_consent/src/Form/ConsentAgreementRevisionRevertForm.php \Drupal\gdpr_consent\Form\ConsentAgreementRevisionRevertForm::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/gdpr_consent/src/Form/ConsentAgreementRevisionRevertForm.php, line 114

Class

ConsentAgreementRevisionRevertForm
Provides a form for reverting a Consent Agreement revision.

Namespace

Drupal\gdpr_consent\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.
  $originalRevisionTimestamp = $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($originalRevisionTimestamp),
  ]);
  $this->revision
    ->save();
  $this
    ->logger('content')
    ->notice('Consent Agreement: reverted %title revision %revision.', [
    '%title' => $this->revision
      ->label(),
    '%revision' => $this->revision
      ->getRevisionId(),
  ]);
  Drupal::messenger()
    ->addMessage($this
    ->t('Consent Agreement %title has been reverted to the revision from %revision-date.', [
    '%title' => $this->revision
      ->label(),
    '%revision-date' => $this->dateFormatter
      ->format($originalRevisionTimestamp),
  ]));
  $form_state
    ->setRedirect('entity.gdpr_consent_agreement.version_history', [
    'gdpr_consent_agreement' => $this->revision
      ->id(),
  ]);
}