You are here

public function EntityWarmer::loadMultiple in Warmer 8

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

Loads multiple items based on their IDs.

Parameters

array: The item IDs.

Return value

array The loaded items.

Overrides WarmerInterface::loadMultiple

File

modules/warmer_entity/src/Plugin/warmer/EntityWarmer.php, line 82

Class

EntityWarmer
The cache warmer for the built-in entity cache.

Namespace

Drupal\warmer_entity\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) {
    try {
      $output += $this->entityTypeManager
        ->getStorage($entity_type_id)
        ->loadMultiple($entity_ids);

      // \Drupal\Core\Entity\EntityStorageBase::buildCacheId() is protected,
      // so we blindly reset the whole static cache instead of specific IDs.
      $this->entityMemoryCache
        ->deleteAll();
    } catch (PluginException $exception) {
      watchdog_exception('warmer', $exception);
    } catch (DatabaseExceptionWrapper $exception) {
      watchdog_exception('warmer', $exception);
    }
  }
  return $output;
}