function EntityResource::loadEntitiesWithAccess

Same name in other branches
  1. 9 core/modules/jsonapi/src/Controller/EntityResource.php \Drupal\jsonapi\Controller\EntityResource::loadEntitiesWithAccess()
  2. 8.9.x core/modules/jsonapi/src/Controller/EntityResource.php \Drupal\jsonapi\Controller\EntityResource::loadEntitiesWithAccess()
  3. 11.x core/modules/jsonapi/src/Controller/EntityResource.php \Drupal\jsonapi\Controller\EntityResource::loadEntitiesWithAccess()

Build a collection of the entities to respond with and access objects.

Parameters

\Drupal\Core\Entity\EntityStorageInterface $storage: The entity storage to load the entities from.

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

bool $load_latest_revisions: Whether to load the latest revisions instead of the defaults.

Return value

array An array of loaded entities and/or an access exceptions.

1 call to EntityResource::loadEntitiesWithAccess()
EntityResource::getCollection in core/modules/jsonapi/src/Controller/EntityResource.php
Gets the collection of entities.

File

core/modules/jsonapi/src/Controller/EntityResource.php, line 1194

Class

EntityResource
Process all entity requests.

Namespace

Drupal\jsonapi\Controller

Code

protected function loadEntitiesWithAccess(EntityStorageInterface $storage, array $ids, $load_latest_revisions) {
    $output = [];
    if ($load_latest_revisions) {
        assert($storage instanceof RevisionableStorageInterface);
        $entities = $storage->loadMultipleRevisions(array_keys($ids));
    }
    else {
        $entities = $storage->loadMultiple($ids);
    }
    foreach ($entities as $entity) {
        $output[$entity->id()] = $this->entityAccessChecker
            ->getAccessCheckedResourceObject($entity);
    }
    return array_values($output);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.