You are here

public function DeveloperStorage::loadMultiple in Apigee Edge 8

We had to override this function because a developer can be referenced by email or developer id (UUID) on Apigee Edge. In Drupal we use the email as primary and because of that if we try to load a developer by UUID then we get back an integer because EntityStorageBase::loadMultiple() returns an array where entities keyed by their Drupal ids.

Overrides EntityStorageBase::loadMultiple

See also

\Drupal\Core\Entity\EntityStorageBase::loadMultiple()

File

src/Entity/Storage/DeveloperStorage.php, line 119

Class

DeveloperStorage
Entity storage implementation for developers.

Namespace

Drupal\apigee_edge\Entity\Storage

Code

public function loadMultiple(array $ids = NULL) {
  $entities = parent::loadMultiple($ids);
  if ($ids) {
    $entities_by_developer_id = array_reduce($entities, function ($carry, $item) {

      // It could be an integer if developer UUID has been used as as an id
      // instead of the email address.
      if (is_object($item)) {

        /** @var \Drupal\apigee_edge\Entity\DeveloperInterface $item */
        $carry[$item
          ->getDeveloperId()] = $item;
      }
      return $carry;
    }, []);
    $entities = array_merge($entities, $entities_by_developer_id);
    $requested_entities = [];

    // Ensure that the returned array is ordered the same as the original
    // $ids array if this was passed in and remove any invalid ids.
    $passed_ids = array_flip(array_intersect_key(array_flip($ids), $entities));
    foreach ($passed_ids as $id) {
      $requested_entities[$id] = $entities[$id];
    }
    $entities = $requested_entities;
  }
  return $entities;
}