You are here

public function UserRevisionRevertForm::submitForm in User Revision 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/UserRevisionRevertForm.php, line 99

Class

UserRevisionRevertForm
Provides a form for reverting a user revision.

Namespace

Drupal\user_revision\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $this->revision
    ->setNewRevision();

  // Make this the new default revision for the user.
  $this->revision
    ->isDefaultRevision(TRUE);

  // The revision timestamp will be updated when the revision is saved. Keep the
  // original one for the confirmation message.
  $original_revision_timestamp = $this->revision->revision_timestamp->value;
  $this->revision->revision_log = t('Copy of the revision from %date.', array(
    '%date' => \Drupal::service('date.formatter')
      ->format($original_revision_timestamp),
  ));
  $this->revision
    ->save();
  $this
    ->logger('user_revision')
    ->notice('user: reverted %name revision %revision.', array(
    '%name' => $this->revision
      ->label(),
    '%revision' => $this->revision
      ->getRevisionId(),
  ));
  $this
    ->messenger()
    ->addStatus(t('User %name has been reverted back to the revision from %revision-date.', array(
    '%name' => $this->revision
      ->label(),
    '%revision-date' => \Drupal::service('date.formatter')
      ->format($original_revision_timestamp),
  )));
  $form_state
    ->setRedirect('entity.user.version_history', array(
    'user' => $this->revision
      ->id(),
  ));
}