ResourceType
class ResourceType (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. |
Value object containing all metadata for a JSON:API resource type.
Used to generate routes (collection, individual, etcetera), generate relationship links, and so on.
Constants
| TYPE_NAME_URI_PATH_SEPARATOR |
A string which is used as path separator in resource type names. |
Properties
| protected string | $entityTypeId | The entity type ID. |
|
| protected string | $bundle | The bundle ID. |
|
| protected string | $typeName | The type name. |
|
| protected string | $deserializationTargetClass | The class to which a payload converts to. |
|
| protected bool | $internal | Whether this resource type is internal. |
|
| protected bool | $isLocatable | Whether this resource type's resources are locatable. |
|
| protected bool | $isMutable | Whether this resource type's resources are mutable. |
|
| protected bool | $isVersionable | Whether this resource type's resources are versionable. |
|
| protected string[] | $fields | The list of fields on the underlying entity type + bundle. |
|
| protected array | $relatableResourceTypesByField | An array of arrays of relatable resource types, keyed by public field name. |
|
| protected string[] | $fieldMapping | The mapping for field aliases: keys=public names, values=internal names. |
Methods
Gets the entity type ID.
Gets the type name.
Gets the bundle.
Gets the deserialization target class.
Translates the entity field name to the public field name.
Translates the public field name to the entity field name.
Gets the attribute and relationship fields of this resource type.
Gets a particular attribute or relationship field by public field name.
Gets a particular attribute or relationship field by internal field name.
Checks if the field exists.
Checks if a field is enabled or not.
Determine whether to include a collection count.
Whether this resource type is internal.
Whether resources of this resource type are locatable.
Whether resources of this resource type are mutable.
Whether resources of this resource type are versionable.
Instantiates a ResourceType object.
Sets the relatable resource types.
Get all resource types with which this type may have a relationship.
Get all resource types with which the given field may have a relationship.
Get the resource path.
Details
string
getEntityTypeId()
Gets the entity type ID.
string
getTypeName()
Gets the type name.
string
getBundle()
Gets the bundle.
string
getDeserializationTargetClass()
Gets the deserialization target class.
string
getPublicName($field_name)
Translates the entity field name to the public field name.
This is only here so we can allow polymorphic implementations to take a greater control on the field names.
string
getInternalName($field_name)
Translates the public field name to the entity field name.
This is only here so we can allow polymorphic implementations to take a greater control on the field names.
ResourceTypeField[]
getFields()
Gets the attribute and relationship fields of this resource type.
ResourceTypeField|null
getFieldByPublicName(string $public_field_name)
Gets a particular attribute or relationship field by public field name.
ResourceTypeField|null
getFieldByInternalName(string $internal_field_name)
Gets a particular attribute or relationship field by internal field name.
bool
hasField(string $field_name)
Checks if the field exists.
Note: a minority of config entity types which do not define a
config_export in their entity type annotation will not have their fields
represented here because it is impossible to determine them without an
instance of config available.
bool
isFieldEnabled(string $field_name)
Checks if a field is enabled or not.
This is only here so we can allow polymorphic implementations to take a greater control on the data model.
bool
includeCount()
Determine whether to include a collection count.
bool
isInternal()
Whether this resource type is internal.
This must not be used as an access control mechanism.
Internal resource types are not available via the HTTP API. They have no
routes and cannot be used for filtering or sorting. They cannot be included
in the response using the include query parameter.
However, relationship fields on public resources will include a resource identifier for the referenced internal resource.
This method exists to remove data that should not logically be exposed by the HTTP API. For example, read-only data from an internal resource might be embedded in a public resource using computed fields. Therefore, including the internal resource as a relationship with distinct routes might unnecessarily expose internal implementation details.
bool
isLocatable()
Whether resources of this resource type are locatable.
A resource type may for example not be locatable when it is not stored.
bool
isMutable()
Whether resources of this resource type are mutable.
Indicates that resources of this type may not be created, updated or deleted (POST, PATCH or DELETE, respectively).
bool
isVersionable()
Whether resources of this resource type are versionable.
__construct(string $entity_type_id, string $bundle, string $deserialization_target_class, bool $internal = FALSE, bool $is_locatable = TRUE, bool $is_mutable = TRUE, bool $is_versionable = FALSE, array $fields = [], null|string $type_name = NULL)
Instantiates a ResourceType object.
setRelatableResourceTypes(array $relatable_resource_types)
Sets the relatable resource types.
array
getRelatableResourceTypes()
Get all resource types with which this type may have a relationship.
ResourceType[]
getRelatableResourceTypesByField(string $field_name)
Get all resource types with which the given field may have a relationship.
string
getPath()
Get the resource path.