You are here

public function ResourceTypeRepository::all in JSON:API 8.2

Same name and namespace in other branches
  1. 8 src/ResourceType/ResourceTypeRepository.php \Drupal\jsonapi\ResourceType\ResourceTypeRepository::all()

Gets all JSON:API resource types.

Return value

\Drupal\jsonapi\ResourceType\ResourceType[] The set of all JSON:API resource types in this Drupal instance.

Overrides ResourceTypeRepositoryInterface::all

2 calls to ResourceTypeRepository::all()
ResourceTypeRepository::get in src/ResourceType/ResourceTypeRepository.php
Gets a specific JSON:API resource type based on entity type ID and bundle.
ResourceTypeRepository::getByTypeName in src/ResourceType/ResourceTypeRepository.php
Gets a specific JSON:API resource type based on a supplied typename.

File

src/ResourceType/ResourceTypeRepository.php, line 99

Class

ResourceTypeRepository
Provides a repository of all JSON:API resource types.

Namespace

Drupal\jsonapi\ResourceType

Code

public function all() {
  $cached = $this->staticCache
    ->get('jsonapi.resource_types', FALSE);
  if ($cached === FALSE) {
    $resource_types = [];
    foreach ($this->entityTypeManager
      ->getDefinitions() as $entity_type) {
      $resource_types = array_merge($resource_types, array_map(function ($bundle) use ($entity_type) {
        return $this
          ->createResourceType($entity_type, $bundle);
      }, array_keys($this->entityTypeBundleInfo
        ->getBundleInfo($entity_type
        ->id()))));
    }
    foreach ($resource_types as $resource_type) {
      $relatable_resource_types = $this
        ->calculateRelatableResourceTypes($resource_type, $resource_types);
      $resource_type
        ->setRelatableResourceTypes($relatable_resource_types);
    }
    $this->staticCache
      ->set('jsonapi.resource_types', $resource_types, Cache::PERMANENT, [
      'jsonapi_resource_types',
    ]);
  }
  return $cached ? $cached->data : $resource_types;
}