function EntityTestHooks::entityPreload

Implements hook_entity_preload().

Loads non-default revision when loading an entity.

Attributes

#[Hook('entity_preload')]

File

core/modules/system/tests/modules/entity_test/src/Hook/EntityTestHooks.php, line 768

Class

EntityTestHooks
Hook implementations for entity_test.

Namespace

Drupal\entity_test\Hook

Code

public function entityPreload(array $ids, string $entity_type_id) : array {
  $entities = [];
  $key_value_store = $this->keyValueStoreFactory
    ->get('entity_test_preload_entities');
  if ($revisions_load = $key_value_store->get($entity_type_id)) {
    foreach ($revisions_load as $id => $revision_id) {
      $revisions = $this->entityTypeManager
        ->getStorage($entity_type_id)
        ->loadMultipleRevisions([
        $revision_id,
      ]);
      $entities[$id] = $revisions[$revision_id];
    }
  }
  return $entities;
}

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