You are here

public function ResourceTypeRepository::get in JSON:API 8

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

Return value

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

Overrides ResourceTypeRepositoryInterface::get

1 call to ResourceTypeRepository::get()
ResourceTypeRepository::getRelatableResourceTypesFromFieldDefinition in src/ResourceType/ResourceTypeRepository.php
Get relatable resource types from a field definition.

File

src/ResourceType/ResourceTypeRepository.php, line 122

Class

ResourceTypeRepository
Provides a repository of all JSON API resource types.

Namespace

Drupal\jsonapi\ResourceType

Code

public function get($entity_type_id, $bundle) {
  if (empty($entity_type_id)) {
    throw new PreconditionFailedHttpException('Server error. The current route is malformed.');
  }
  foreach ($this
    ->all() as $resource) {
    if ($resource
      ->getEntityTypeId() == $entity_type_id && $resource
      ->getBundle() == $bundle) {
      return $resource;
    }
  }
  return NULL;
}