You are here

public function ResourceTypeRepository::all in JSON:API 8

Same name and namespace in other branches
  1. 8.2 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 95

Class

ResourceTypeRepository
Provides a repository of all JSON API resource types.

Namespace

Drupal\jsonapi\ResourceType

Code

public function all() {
  if (!$this->all) {
    $entity_type_ids = array_keys($this->entityTypeManager
      ->getDefinitions());
    foreach ($entity_type_ids as $entity_type_id) {
      $resource_type_class = static::RESOURCE_TYPE_CLASS;
      $this->all = array_merge($this->all, array_map(function ($bundle) use ($entity_type_id, $resource_type_class) {
        $entity_type = $this->entityTypeManager
          ->getDefinition($entity_type_id);
        return new $resource_type_class($entity_type_id, $bundle, $entity_type
          ->getClass(), static::shouldBeInternalResourceType($entity_type), static::isLocatableResourceType($entity_type));
      }, array_keys($this->entityTypeBundleInfo
        ->getBundleInfo($entity_type_id))));
    }
    foreach ($this->all as $resource_type) {
      $relatable_resource_types = $this
        ->calculateRelatableResourceTypes($resource_type);
      $resource_type
        ->setRelatableResourceTypes($relatable_resource_types);
    }
  }
  return $this->all;
}