function RevisionRevertForm::submitForm

Same name in other branches
  1. 10 core/lib/Drupal/Core/Entity/Form/RevisionRevertForm.php \Drupal\Core\Entity\Form\RevisionRevertForm::submitForm()

Overrides FormInterface::submitForm

File

core/lib/Drupal/Core/Entity/Form/RevisionRevertForm.php, line 158

Class

RevisionRevertForm
Provides a form for reverting an entity revision.

Namespace

Drupal\Core\Entity\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
    $revisionId = $this->revision
        ->getRevisionId();
    $revisionLabel = $this->revision
        ->label();
    $bundleLabel = $this->getBundleLabel($this->revision);
    if ($this->revision instanceof RevisionLogInterface) {
        $originalRevisionTimestamp = $this->revision
            ->getRevisionCreationTime();
    }
    $this->revision = $this->prepareRevision($this->revision, $form_state);
    if (isset($originalRevisionTimestamp)) {
        $date = $this->dateFormatter
            ->format($originalRevisionTimestamp);
        $this->messenger
            ->addMessage($this->t('@type %title has been reverted to the revision from %revision-date.', [
            '@type' => $bundleLabel,
            '%title' => $revisionLabel,
            '%revision-date' => $date,
        ]));
    }
    else {
        $this->messenger
            ->addMessage($this->t('@type %title has been reverted.', [
            '@type' => $bundleLabel,
            '%title' => $revisionLabel,
        ]));
    }
    $this->logger($this->revision
        ->getEntityType()
        ->getProvider())
        ->info('@type: reverted %title revision %revision.', [
        '@type' => $this->revision
            ->bundle(),
        '%title' => $revisionLabel,
        '%revision' => $revisionId,
    ]);
    $versionHistoryUrl = $this->revision
        ->toUrl('version-history');
    if ($versionHistoryUrl->access($this->currentUser())) {
        $form_state->setRedirectUrl($versionHistoryUrl);
    }
    if (!$form_state->getRedirect()) {
        $canonicalUrl = $this->revision
            ->toUrl();
        if ($canonicalUrl->access($this->currentUser())) {
            $form_state->setRedirectUrl($canonicalUrl);
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.