function RevisionRevertForm::prepareRevision

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

Prepares a revision to be reverted.

Parameters

\Drupal\Core\Entity\RevisionableInterface $revision: The revision to be reverted.

\Drupal\Core\Form\FormStateInterface $formState: The current state of the form.

Return value

\Drupal\Core\Entity\RevisionableInterface The new revision, the same type as passed to $revision.

1 call to RevisionRevertForm::prepareRevision()
RevisionRevertForm::submitForm in core/lib/Drupal/Core/Entity/Form/RevisionRevertForm.php

File

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

Class

RevisionRevertForm
Provides a form for reverting an entity revision.

Namespace

Drupal\Core\Entity\Form

Code

protected function prepareRevision(RevisionableInterface $revision, FormStateInterface $formState) : RevisionableInterface {
    $storage = $this->entityTypeManager
        ->getStorage($revision->getEntityTypeId());
    if (!$storage instanceof RevisionableStorageInterface) {
        throw new \LogicException('Revisionable entities are expected to implement RevisionableStorageInterface');
    }
    $revision = $storage->createRevision($revision);
    $time = $this->time
        ->getRequestTime();
    if ($revision instanceof EntityChangedInterface) {
        $revision->setChangedTime($time);
    }
    if ($revision instanceof RevisionLogInterface) {
        $originalRevisionTimestamp = $revision->getRevisionCreationTime();
        $date = $this->dateFormatter
            ->format($originalRevisionTimestamp);
        $revision->setRevisionLogMessage($this->t('Copy of the revision from %date.', [
            '%date' => $date,
        ]))
            ->setRevisionCreationTime($time)
            ->setRevisionUserId($this->currentUser()
            ->id());
    }
    return $revision;
}

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