You are here

public function RevisionRevertForm::submitForm in Entity API 8

Same name and namespace in other branches
  1. 8.0 src/Form/RevisionRevertForm.php \Drupal\entity\Form\RevisionRevertForm::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

src/Form/RevisionRevertForm.php, line 114

Class

RevisionRevertForm

Namespace

Drupal\entity\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.
  $this->revision = $this
    ->prepareRevision($this->revision);
  if ($this->revision instanceof RevisionLogInterface) {
    $original_revision_timestamp = $this->revision
      ->getRevisionCreationTime();
    $this->revision
      ->setRevisionLogMessage($this
      ->t('Copy of the revision from %date.', [
      '%date' => $this->dateFormatter
        ->format($original_revision_timestamp),
    ]));
    $this
      ->messenger()
      ->addStatus(t('@type %title has been reverted to the revision from %revision-date.', [
      '@type' => $this
        ->getBundleLabel($this->revision),
      '%title' => $this->revision
        ->label(),
      '%revision-date' => $this->dateFormatter
        ->format($original_revision_timestamp),
    ]));
  }
  else {
    $this
      ->messenger()
      ->addStatus(t('@type %title has been reverted', [
      '@type' => $this
        ->getBundleLabel($this->revision),
      '%title' => $this->revision
        ->label(),
    ]));
  }
  $this->revision
    ->save();
  $this
    ->logger('content')
    ->notice('@type: reverted %title revision %revision.', [
    '@type' => $this->revision
      ->bundle(),
    '%title' => $this->revision
      ->label(),
    '%revision' => $this->revision
      ->getRevisionId(),
  ]);
  $form_state
    ->setRedirect("entity.{$this->revision->getEntityTypeId()}.version_history", [
    $this->revision
      ->getEntityTypeId() => $this->revision
      ->id(),
  ]);
}