You are here

final protected function EdgeEntityStorageBase::processLoadedEntities in Apigee Edge 8

Processes loaded (SDK) entities to Drupal entities.

This method also ensured that storage hooks gets called and entities gets saved to the persistent cache before they gets returned.

Parameters

array|null $ids: Originally request entity ids.

array $sdk_entities: The loaded SDK entities by the entity controller for the requested ids.

Return value

array Array of Drupal entities.

Throws

\Drupal\Core\Entity\EntityStorageException If Drupal entity ids could not be resolved.

2 calls to EdgeEntityStorageBase::processLoadedEntities()
AppStorage::getFromStorage in src/Entity/Storage/AppStorage.php
Gets entities from the storage.
EdgeEntityStorageBase::getFromStorage in src/Entity/Storage/EdgeEntityStorageBase.php
Gets entities from the storage.

File

src/Entity/Storage/EdgeEntityStorageBase.php, line 304

Class

EdgeEntityStorageBase
Base entity storage class for Apigee Edge entities.

Namespace

Drupal\apigee_edge\Entity\Storage

Code

protected final function processLoadedEntities(?array $ids, array $sdk_entities) : array {
  $entities = [];

  // Returned entities are SDK entities and not Drupal entities,
  // what if the id is used in Drupal is different than what
  // SDK uses? (ex.: developer)
  foreach ($sdk_entities as $entity) {
    $drupal_entity = $this
      ->createNewInstance($entity);
    if ($ids === NULL) {
      $entities[$drupal_entity
        ->id()] = $drupal_entity;
    }
    elseif ($referenced_ids = array_intersect($drupal_entity
      ->uniqueIds(), $ids)) {
      if (count($referenced_ids) > 1) {

        // Sanity check, why would someone try to load the same entity
        // by using more than one of its unique id.
        throw new EntityStorageException(sprintf('The same entity should be referenced only with one id, got %s.', implode('', $referenced_ids)));
      }
      $entities[reset($referenced_ids)] = $drupal_entity;
    }
  }
  $this
    ->invokeStorageLoadHook($entities);
  $this
    ->setPersistentCache($entities);
  return $entities;
}