invokeStorageLoadHook example

/** * {@inheritdoc} */
  protected function doLoadMultiple(array $ids = NULL) {
    // Attempt to load entities from the persistent cache. This will remove IDs     // that were loaded from $ids.     $entities_from_cache = $this->getFromPersistentCache($ids);

    // Load any remaining entities from the database.     if ($entities_from_storage = $this->getFromStorage($ids)) {
      $this->invokeStorageLoadHook($entities_from_storage);
      $this->setPersistentCache($entities_from_storage);
    }

    return $entities_from_cache + $entities_from_storage;
  }

  /** * Gets entities from the storage. * * @param array|null $ids * If not empty, return entities that match these IDs. Return all entities * when NULL. * * @return \Drupal\Core\Entity\ContentEntityInterface[] * Array of entities from the storage. */
    $entity_groups = [];
    $entity_group_mapping = [];
    foreach ($revisions as $revision) {
      $entity_id = $revision->id();
      $entity_group_key = isset($entity_group_mapping[$entity_id]) ? $entity_group_mapping[$entity_id] + 1 : 0;
      $entity_group_mapping[$entity_id] = $entity_group_key;
      $entity_groups[$entity_group_key][$entity_id] = $revision;
    }

    // Invoke the entity hooks for each group.     foreach ($entity_groups as $entities) {
      $this->invokeStorageLoadHook($entities);
      $this->postLoad($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.     if ($revision_ids) {
      $flipped_ids = array_intersect_key(array_flip($revision_ids)$revisions);
      $revisions = array_replace($flipped_ids$revisions);
    }

    return $revisions;
  }
Home | Imprint | This part of the site doesn't use cookies.