You are here

public function ConfigEntityRevisionsRevertFormBase::prepareRevertedRevision in Config Entity Revisions 1.x

Same name and namespace in other branches
  1. 8.2 src/ConfigEntityRevisionsRevertFormBase.php \Drupal\config_entity_revisions\ConfigEntityRevisionsRevertFormBase::prepareRevertedRevision()
  2. 8 src/ConfigEntityRevisionsRevertFormBase.php \Drupal\config_entity_revisions\ConfigEntityRevisionsRevertFormBase::prepareRevertedRevision()

Prepares a revision to be reverted.

Parameters

ConfigEntityRevisionsEntityInterface $revision: The revision to be reverted.

Return value

ConfigEntityRevisionsEntityInterface The prepared revision ready to be stored.

1 call to ConfigEntityRevisionsRevertFormBase::prepareRevertedRevision()
ConfigEntityRevisionsRevertFormBase::applyRevisionChange in src/ConfigEntityRevisionsRevertFormBase.php
Apply the revision insert/update.
1 method overrides ConfigEntityRevisionsRevertFormBase::prepareRevertedRevision()
ConfigEntityRevisionsRevertFormTest2::prepareRevertedRevision in tests/src/Unit/ConfigEntityRevisionsRevertFormBaseTest.php
Override prepareRevertedRevision so we can be sure it is actually called.

File

src/ConfigEntityRevisionsRevertFormBase.php, line 186

Class

ConfigEntityRevisionsRevertFormBase
Provides a form for reverting / publishing a revision.

Namespace

Drupal\config_entity_revisions

Code

public function prepareRevertedRevision(ConfigEntityRevisionsEntityInterface $revision) {
  $revision
    ->setNewRevision();
  $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 = $revision
    ->getRevisionCreationTime();
  $originalLogMessage = $revision
    ->getRevisionLogMessage();
  $logMessage = $originalLogMessage ? $this
    ->t('Copy of the revision from %date (%message).', [
    '%date' => $this->dateFormatter
      ->format($original_revision_timestamp),
    '%message' => $originalLogMessage,
  ]) : $this
    ->t('Copy of the revision from %date.', [
    '%date' => $this->dateFormatter
      ->format($original_revision_timestamp),
  ]);
  $revision
    ->setRevisionLogMessage($logMessage);
  $revision
    ->setRevisionUserId($this
    ->currentUser()
    ->id());
  $revision
    ->setRevisionCreationTime($this->time
    ->getRequestTime());
  $revision
    ->setChangedTime($this->time
    ->getRequestTime());
  $revision
    ->set('moderation_state', 'draft');
  $revision
    ->setUnpublished();
  return $revision;
}