class ResourceTypeRepository implements ResourceTypeRepositoryInterface (View source)

internal  JSON:API maintains no PHP API since its API is the HTTP API. This class may change at any time and this will break any dependencies on it.
 

Provides a repository of all JSON:API resource types.

Contains the complete set of ResourceType value objects, which are auto- generated based on the Entity Type Manager and Entity Type Bundle Info: one JSON:API resource type per entity type bundle. So, for example:

  • node--article
  • node--page
  • node--…
  • user--user

Properties

protected EntityTypeManagerInterface $entityTypeManager

The entity type manager.

protected EntityTypeBundleInfoInterface $entityTypeBundleInfo

The bundle manager.

protected EntityFieldManagerInterface $entityFieldManager

The entity field manager.

protected CacheBackendInterface $cache

The cache backend.

protected EventDispatcherInterface $eventDispatcher

The event dispatcher.

protected string[] $cacheTags

Cache tags used for caching the repository.

Methods

__construct(EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $entity_bundle_info, EntityFieldManagerInterface $entity_field_manager, CacheBackendInterface $cache, EventDispatcherInterface $dispatcher)

Instantiates a ResourceTypeRepository object.

all()

Gets all JSON:API resource types.

createResourceType(EntityTypeInterface $entity_type, string $bundle)

Creates a ResourceType value object for the given entity type + bundle.

get(string $entity_type_id, string $bundle)

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

getByTypeName(string $type_name)

Gets a specific JSON:API resource type based on a supplied typename.

getFields(array $field_names, EntityTypeInterface $entity_type, string $bundle)

Gets the field mapping for the given field names and entity type + bundle.

string[]
getAllFieldNames(EntityTypeInterface $entity_type, string $bundle)

Gets all field names for a given entity type and bundle.

static bool
isMutableResourceType(EntityTypeInterface $entity_type, string $bundle)

Whether an entity type + bundle maps to a mutable resource type.

static bool
isLocatableResourceType(EntityTypeInterface $entity_type, string $bundle)

Whether an entity type + bundle maps to a locatable resource type.

static bool
isVersionableResourceType(EntityTypeInterface $entity_type)

Whether an entity type is a versionable resource type.

array
calculateRelatableResourceTypes(ResourceType $resource_type, array $resource_types)

Calculates relatable JSON:API resource types for a given resource type.

getRelatableResourceTypesFromFieldDefinition(FieldDefinitionInterface $field_definition, array $resource_types)

Get relatable resource types from a field definition.

bool
isReferenceFieldDefinition(FieldDefinitionInterface $field_definition)

Determines if a given field definition is a reference field.

string[]
getAllBundlesForEntityType(string $entity_type_id)

Gets all bundle IDs for a given entity type.

static ResourceType|null
lookupResourceType(array $resource_types, string $entity_type_id, string $bundle)

Lookup a resource type by entity type ID and bundle name.

Details

__construct(EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $entity_bundle_info, EntityFieldManagerInterface $entity_field_manager, CacheBackendInterface $cache, EventDispatcherInterface $dispatcher)

Instantiates a ResourceTypeRepository object.

Parameters

EntityTypeManagerInterface $entity_type_manager

The entity type manager.

EntityTypeBundleInfoInterface $entity_bundle_info

The entity type bundle info service.

EntityFieldManagerInterface $entity_field_manager

The entity field manager.

CacheBackendInterface $cache

The cache backend.

EventDispatcherInterface $dispatcher

The event dispatcher.

ResourceType[] all()

Gets all JSON:API resource types.

Return Value

ResourceType[]

The set of all JSON:API resource types in this Drupal instance.

protected ResourceType createResourceType(EntityTypeInterface $entity_type, string $bundle)

Creates a ResourceType value object for the given entity type + bundle.

Parameters

EntityTypeInterface $entity_type

The entity type to create a JSON:API resource type for.

string $bundle

The entity type bundle to create a JSON:API resource type for.

Return Value

ResourceType

A JSON:API resource type.

ResourceType get(string $entity_type_id, string $bundle)

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

ResourceType

The requested JSON:API resource type, if it exists. NULL otherwise.

ResourceType|null getByTypeName(string $type_name)

Gets a specific JSON:API resource type based on a supplied typename.

Parameters

string $type_name

The public typename of a JSON:API resource.

Return Value

ResourceType|null

The resource type, or NULL if none found.

protected ResourceTypeField[] getFields(array $field_names, EntityTypeInterface $entity_type, string $bundle)

Gets the field mapping for the given field names and entity type + bundle.

Parameters

array $field_names

All field names on a bundle of the given entity type.

EntityTypeInterface $entity_type

The entity type for which to get the field mapping.

string $bundle

The bundle to assess.

Return Value

ResourceTypeField[]

An array of JSON:API resource type fields keyed by internal field names.

protected string[] getAllFieldNames(EntityTypeInterface $entity_type, string $bundle)

Gets all field names for a given entity type and bundle.

Parameters

EntityTypeInterface $entity_type

The entity type for which to get all field names.

string $bundle

The bundle for which to get all field names.

Return Value

string[]

All field names.

static protected bool isMutableResourceType(EntityTypeInterface $entity_type, string $bundle)

Whether an entity type + bundle maps to a mutable resource type.

Parameters

EntityTypeInterface $entity_type

The entity type to assess.

string $bundle

The bundle to assess.

Return Value

bool

TRUE if the entity type is mutable, FALSE otherwise.

static protected bool isLocatableResourceType(EntityTypeInterface $entity_type, string $bundle)

Whether an entity type + bundle maps to a locatable resource type.

Parameters

EntityTypeInterface $entity_type

The entity type to assess.

string $bundle

The bundle to assess.

Return Value

bool

TRUE if the entity type is locatable, FALSE otherwise.

static protected bool isVersionableResourceType(EntityTypeInterface $entity_type)

Whether an entity type is a versionable resource type.

Parameters

EntityTypeInterface $entity_type

The entity type to assess.

Return Value

bool

TRUE if the entity type is versionable, FALSE otherwise.

protected array calculateRelatableResourceTypes(ResourceType $resource_type, array $resource_types)

Calculates relatable JSON:API resource types for a given resource type.

This method has no affect after being called once.

Parameters

ResourceType $resource_type

The resource type repository.

array $resource_types

A list of JSON:API resource types.

Return Value

array

The relatable JSON:API resource types, keyed by field name.

protected ResourceType[] getRelatableResourceTypesFromFieldDefinition(FieldDefinitionInterface $field_definition, array $resource_types)

Get relatable resource types from a field definition.

Parameters

FieldDefinitionInterface $field_definition

The field definition from which to calculate relatable JSON:API resource types.

array $resource_types

A list of JSON:API resource types.

Return Value

ResourceType[]

The JSON:API resource types with which the given field may have a relationship.

protected bool isReferenceFieldDefinition(FieldDefinitionInterface $field_definition)

Determines if a given field definition is a reference field.

Parameters

FieldDefinitionInterface $field_definition

The field definition to inspect.

Return Value

bool

TRUE if the field definition is found to be a reference field. FALSE otherwise.

protected string[] getAllBundlesForEntityType(string $entity_type_id)

Gets all bundle IDs for a given entity type.

Parameters

string $entity_type_id

The entity type for which to get bundles.

Return Value

string[]

The bundle IDs.

static protected ResourceType|null lookupResourceType(array $resource_types, string $entity_type_id, string $bundle)

Lookup a resource type by entity type ID and bundle name.

Parameters

array $resource_types

The list of resource types to do a lookup.

string $entity_type_id

The entity type of a seekable resource type.

string $bundle

The entity bundle of a seekable resource type.

Return Value

ResourceType|null

The resource type or NULL if one cannot be found.