You are here

public function ViewRevisionsRevisionStorage::loadRevision in Config Entity Revisions 8.2

File

modules/view_revisions/src/ViewRevisionsRevisionStorage.php, line 18

Class

ViewRevisionsRevisionStorage
Class ViewRevisionsRevisionStorage.

Namespace

Drupal\view_revisions

Code

public function loadRevision($revision_id) {
  $this
    ->ensure_revision_states_loaded();
  $content_entity_record = array_pop(array_filter($this->revision_states, function ($item) use ($revision_id) {
    return $item->revision == $revision_id;
  }));
  $content_entity_record = $content_entity_record->configuration;
  if (!$content_entity_record) {
    return NULL;
  }
  $entity = \Drupal::getContainer()
    ->get('serializer')
    ->deserialize($content_entity_record, $this
    ->getEntityType()
    ->getClass(), 'json');

  // The result of serialising and then deserialising is not an exact
  // copy of the original. This causes problems downstream if we don't fix
  // a few attributes here.
  $entity
    ->set('settingsOriginal', $entity
    ->get('settings'));
  $entity
    ->set('enforceIsNew', FALSE);

  // Record the revision ID in the config entity so we can quickly and
  // easily access the revision record if needed (eg for edit form revision
  // message).
  $entity
    ->updateLoadedRevisionId($revision_id);
  return $entity;
}