EntityResource
class EntityResource (View source)
| internal | JSON:API maintains no PHP API. The API is the HTTP API. This class may change at any time and could break any dependencies on it. |
Process all entity requests.
Traits
Provides a method to validate an entity.
Properties
| protected EntityTypeManagerInterface | $entityTypeManager | The entity type manager. |
|
| protected EntityFieldManagerInterface | $fieldManager | The field manager. |
|
| protected ResourceTypeRepositoryInterface | $resourceTypeRepository | The resource type repository. |
|
| protected RendererInterface | $renderer | The renderer. |
|
| protected EntityRepositoryInterface | $entityRepository | The entity repository. |
|
| protected IncludeResolver | $includeResolver | The include resolver. |
|
| protected EntityAccessChecker | $entityAccessChecker | The JSON:API entity access checker. |
|
| protected FieldResolver | $fieldResolver | The JSON:API field resolver. |
|
| protected SerializerInterface|DenormalizerInterface | $serializer | The JSON:API serializer. |
|
| protected TimeInterface | $time | The time service. |
|
| protected AccountInterface | $user | The current user account. |
Methods
Verifies that an entity does not violate any validation constraints.
Instantiates an EntityResource object.
Patches an individual entity.
Executes the query in a render context, to catch bubbled cacheability.
Gets the related resource.
Gets the relationship of an entity.
Adds a relationship to a to-many relationship.
Updates the relationship of an entity.
Update a to-one relationship.
Update a to-many relationship.
Deletes the relationship of an entity.
Deserializes a request body, if any.
Gets a basic query for a collection.
Gets a basic query for a collection count.
Loads the entity targeted by a resource identifier.
Determines if the client needs to be updated with new relationship data.
Builds a response with the appropriate wrapped document.
Respond with an entity collection.
Takes a field from the origin entity and puts it to the destination entity.
Gets includes for the given response data.
Checks whether the given field should be PATCHed.
Build a collection of the entities to respond with and access objects.
Extracts JSON:API query parameters from the request.
Get the full URL for a given request object.
Get the pager links for a given request object.
Get the query param array.
Details
static protected
validate(EntityInterface $entity, array $field_names = NULL)
Verifies that an entity does not violate any validation constraints.
__construct(EntityTypeManagerInterface $entity_type_manager, EntityFieldManagerInterface $field_manager, ResourceTypeRepositoryInterface $resource_type_repository, RendererInterface $renderer, EntityRepositoryInterface $entity_repository, IncludeResolver $include_resolver, EntityAccessChecker $entity_access_checker, FieldResolver $field_resolver, SerializerInterface $serializer, TimeInterface $time, AccountInterface $user)
Instantiates an EntityResource object.
ResourceResponse
getIndividual(EntityInterface $entity, Request $request)
Gets the individual entity.
ResourceResponse
createIndividual(ResourceType $resource_type, Request $request)
Creates an individual entity.
ResourceResponse
patchIndividual(ResourceType $resource_type, EntityInterface $entity, Request $request)
Patches an individual entity.
ResourceResponse
deleteIndividual(EntityInterface $entity)
Deletes an individual entity.
ResourceResponse
getCollection(ResourceType $resource_type, Request $request)
Gets the collection of entities.
protected int|array
executeQueryInRenderContext(QueryInterface $query, CacheableMetadata $query_cacheability)
Executes the query in a render context, to catch bubbled cacheability.
ResourceResponse
getRelated(ResourceType $resource_type, FieldableEntityInterface $entity, string $related, Request $request)
Gets the related resource.
ResourceResponse
getRelationship(ResourceType $resource_type, FieldableEntityInterface $entity, string $related, Request $request, int $response_code = 200)
Gets the relationship of an entity.
ResourceResponse
addToRelationshipData(ResourceType $resource_type, FieldableEntityInterface $entity, string $related, Request $request)
Adds a relationship to a to-many relationship.
ResourceResponse
replaceRelationshipData(ResourceType $resource_type, EntityInterface $entity, string $related, Request $request)
Updates the relationship of an entity.
protected
doPatchIndividualRelationship(EntityInterface $entity, array $resource_identifiers, FieldDefinitionInterface $field_definition)
Update a to-one relationship.
protected
doPatchMultipleRelationship(EntityInterface $entity, array $resource_identifiers, FieldDefinitionInterface $field_definition)
Update a to-many relationship.
ResourceResponse
removeFromRelationshipData(ResourceType $resource_type, EntityInterface $entity, string $related, Request $request)
Deletes the relationship of an entity.
protected array
deserialize(ResourceType $resource_type, Request $request, string $class, string $relationship_field_name = NULL)
Deserializes a request body, if any.
protected QueryInterface
getCollectionQuery(ResourceType $resource_type, array $params, CacheableMetadata $query_cacheability)
Gets a basic query for a collection.
protected QueryInterface
getCollectionCountQuery(ResourceType $resource_type, array $params, CacheableMetadata $query_cacheability)
Gets a basic query for a collection count.
protected EntityInterface
getEntityFromResourceIdentifier(ResourceIdentifier $resource_identifier)
Loads the entity targeted by a resource identifier.
static protected bool
relationshipResponseRequiresBody(array $received_resource_identifiers, array $final_resource_identifiers)
Determines if the client needs to be updated with new relationship data.
protected ResourceResponse
buildWrappedResponse(TopLevelDataInterface $data, Request $request, IncludedData $includes, int $response_code = 200, array $headers = [], LinkCollection $links = NULL, array $meta = [])
Builds a response with the appropriate wrapped document.
protected ResourceResponse
respondWithCollection(ResourceObjectData $primary_data, Data $includes, Request $request, ResourceType $resource_type, OffsetPage $page_param)
Respond with an entity collection.
protected
updateEntityField(ResourceType $resource_type, EntityInterface $origin, EntityInterface $destination, string $field_name)
Takes a field from the origin entity and puts it to the destination entity.
Data
getIncludes(Request $request, ResourceObject|ResourceObjectData $data)
Gets includes for the given response data.
protected bool
checkPatchFieldAccess(FieldItemListInterface $original_field, FieldItemListInterface $received_field)
| internal |
Checks whether the given field should be PATCHed.
protected array
loadEntitiesWithAccess(EntityStorageInterface $storage, array $ids, bool $load_latest_revisions)
Build a collection of the entities to respond with and access objects.
protected bool
entityExists(EntityInterface $entity)
Checks if the given entity exists.
protected array
getJsonApiParams(Request $request, ResourceType $resource_type)
Extracts JSON:API query parameters from the request.
static protected Url
getRequestLink(Request $request, array|null $query = NULL)
Get the full URL for a given request object.
static protected LinkCollection
getPagerLinks(Request $request, OffsetPage $page_param, array $link_context = [])
Get the pager links for a given request object.
static protected array
getPagerQueries(string $link_id, int $offset, int $size, array $query = [], int $total = 0)
Get the query param array.