You are here

public function ResourceTypeRepository::get in Drupal 9

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

Gets a specific JSON:API resource type based on entity type ID and bundle.

Parameters

string $entity_type_id: The entity type ID.

string $bundle: The ID for the bundle to find. If the entity type does not have a bundle, then the entity type ID again.

Return value

\Drupal\jsonapi\ResourceType\ResourceType The requested JSON:API resource type, if it exists. NULL otherwise.

Overrides ResourceTypeRepositoryInterface::get

See also

\Drupal\Core\Entity\EntityInterface::bundle()

File

core/modules/jsonapi/src/ResourceType/ResourceTypeRepository.php, line 183

Class

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

Namespace

Drupal\jsonapi\ResourceType

Code

public function get($entity_type_id, $bundle) {
  assert(is_string($bundle) && !empty($bundle), 'A bundle ID is required. Bundleless entity types should pass the entity type ID again.');
  if (empty($entity_type_id)) {
    throw new PreconditionFailedHttpException('Server error. The current route is malformed.');
  }
  $map_id = sprintf('jsonapi.resource_type.%s.%s', $entity_type_id, $bundle);
  $cached = $this->cache
    ->get($map_id);
  if ($cached) {
    return $cached->data;
  }
  $resource_type = static::lookupResourceType($this
    ->all(), $entity_type_id, $bundle);
  $this->cache
    ->set($map_id, $resource_type, Cache::PERMANENT, $this->cacheTags);
  return $resource_type;
}