You are here

public function ConfigEntityRevisionsRevertFormBase::prepareRevertedRevision in Config Entity Revisions 8.2

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

Prepares a revision to be reverted.

Parameters

\Drupal\config_entity_revisions\ConfigEntityRevisions $revision: The revision to be reverted.

Return value

\Drupal\config_entity_revisions\ConfigEntityRevisionsConfigEntityInterface 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 190

Class

ConfigEntityRevisionsRevertFormBase
Class ConfigEntityRevisionsRevertFormBase.

Namespace

Drupal\config_entity_revisions

Code

public function prepareRevertedRevision(ConfigEntityRevisions $revision) {
  $revision
    ->setNewRevision();
  $revision
    ->isDefaultRevision(FALSE);

  // 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());

  // Get the $moderation_state_id for a draft revision.
  // If moderation isn't being used, keep the publication state from the
  // source revision.*
  if ($revision
    ->hasField('moderation_state')) {
    $revision
      ->set('moderation_state', 'draft');
    $revision
      ->setUnpublished();
  }
  return $revision;
}