You are here

private function EntityQueryResourceBase::loadResourceObjectsByEntityIds in JSON:API Resources 8

Loads and access checks entities loaded by ID as JSON:API resource objects.

Parameters

string $entity_type_id: The entity type ID of the entities to load.

int[] $ids: An array of entity IDs, keyed by revision ID if the entity type is revisionable.

bool $load_latest_revisions: (optional) Whether to load the latest revisions instead of the defaults. Defaults to FALSE.

bool $check_access: (optional) Whether to check access on the loaded entities or not. Defaults to TRUE.

Return value

\Drupal\jsonapi\JsonApiResource\ResourceObjectData A ResourceObjectData object containing a resource object with unlimited cardinality. This corresponds to a top-level document's primary data on a collection response.

Throws

\Drupal\Component\Plugin\Exception\PluginNotFoundException Thrown if the entity type doesn't exist.

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException Thrown if the storage handler couldn't be loaded.

1 call to EntityQueryResourceBase::loadResourceObjectsByEntityIds()
EntityQueryResourceBase::loadResourceObjectDataFromEntityQuery in src/Resource/EntityQueryResourceBase.php
Finds entity resource object using an entity query.

File

src/Resource/EntityQueryResourceBase.php, line 125

Class

EntityQueryResourceBase
Defines basic functionality for an entity query-oriented JSON:API Resource.

Namespace

Drupal\jsonapi_resources\Resource

Code

private function loadResourceObjectsByEntityIds($entity_type_id, array $ids, $load_latest_revisions = FALSE, $check_access = TRUE) : ResourceObjectData {
  $storage = $this->entityTypeManager
    ->getStorage($entity_type_id);
  if ($load_latest_revisions) {
    assert($storage instanceof RevisionableStorageInterface);
    $entities = $storage
      ->loadMultipleRevisions(array_keys($ids));
  }
  else {
    $entities = $storage
      ->loadMultiple($ids);
  }
  return $this
    ->createCollectionDataFromEntities($entities, $check_access);
}