You are here

public function CachedPaginatedEntityListingControllerTrait::getEntities in Apigee Edge 8

File

src/Entity/Controller/CachedPaginatedEntityListingControllerTrait.php, line 48

Class

CachedPaginatedEntityListingControllerTrait
For those controllers that supports paginated entity listing.

Namespace

Drupal\apigee_edge\Entity\Controller

Code

public function getEntities(PagerInterface $pager = NULL, string $key_provider = 'id') : array {
  if ($this
    ->entityCache()
    ->isAllEntitiesInCache()) {
    if ($pager === NULL) {
      return $this
        ->entityCache()
        ->getEntities();
    }
    else {
      return $this
        ->extractSubsetOfAssociativeArray($this
        ->entityCache()
        ->getEntities(), $pager
        ->getLimit(), $pager
        ->getStartKey());
    }
  }
  $entities = $this
    ->decorated()
    ->getEntities($pager, $key_provider);
  $this
    ->entityCache()
    ->saveEntities($entities);
  if ($pager === NULL) {
    $this
      ->entityCache()
      ->allEntitiesInCache(TRUE);
  }
  return $entities;
}