You are here

public function ResourceWarmer::loadMultiple in JSON:API Boost 8

Same name and namespace in other branches
  1. 2.x src/Plugin/warmer/ResourceWarmer.php \Drupal\jsonapi_boost\Plugin\warmer\ResourceWarmer::loadMultiple()

Loads multiple items based on their IDs.

Parameters

array: The item IDs.

Return value

array The loaded items.

Overrides WarmerInterface::loadMultiple

File

src/Plugin/warmer/ResourceWarmer.php, line 100

Class

ResourceWarmer
Warms JSON:API resources.

Namespace

Drupal\jsonapi_boost\Plugin\warmer

Code

public function loadMultiple(array $ids = []) {
  $ids_per_type = array_reduce($ids, function ($carry, $id) {
    list($entity_type_id, $entity_id, ) = explode(':', $id);
    if (empty($carry[$entity_type_id])) {
      $carry[$entity_type_id] = [];
    }
    $carry[$entity_type_id][] = $entity_id;
    return $carry;
  }, []);
  $output = [];
  foreach ($ids_per_type as $entity_type_id => $entity_ids) {
    $output += $this->entityTypeManager
      ->getStorage($entity_type_id)
      ->loadMultiple($entity_ids);
  }
  return $output;
}