class FileUpload (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.
 

Handles file upload requests.

Traits

Provides a method to validate an entity.

Properties

protected AccountInterface $currentUser

The current user making the request.

protected EntityFieldManagerInterface $fieldManager

The field manager.

protected TemporaryJsonapiFileFieldUploader $fileUploader

The file uploader.

protected HttpKernelInterface $httpKernel

An HTTP kernel for making subrequests.

Methods

static 
validate(EntityInterface $entity, array $field_names = NULL)

Verifies that an entity does not violate any validation constraints.

__construct(AccountInterface $current_user, EntityFieldManagerInterface $field_manager, TemporaryJsonapiFileFieldUploader $file_uploader, HttpKernelInterface $http_kernel)

Creates a new FileUpload instance.

handleFileUploadForExistingResource(Request $request, ResourceType $resource_type, string $file_field_name, FieldableEntityInterface $entity)

Handles JSON:API file upload requests.

handleFileUploadForNewResource(Request $request, ResourceType $resource_type, string $file_field_name)

Handles JSON:API file upload requests.

static 
ensureFileUploadAccess(AccountInterface $account, FieldDefinitionInterface $field_definition, FieldableEntityInterface $entity = NULL)

Ensures that the given account is allowed to upload a file.

validateAndLoadFieldDefinition(string $entity_type_id, string $bundle, string $field_name)

Validates and loads a field definition instance.

Details

static protected validate(EntityInterface $entity, array $field_names = NULL)

Verifies that an entity does not violate any validation constraints.

Parameters

EntityInterface $entity

The entity object.

array $field_names

(optional) An array of field names. If specified, filters the violations list to include only this set of fields. Defaults to NULL, which means that all violations will be reported.

Exceptions

UnprocessableHttpEntityException

See also

EntityResourceValidationTrait::validate

__construct(AccountInterface $current_user, EntityFieldManagerInterface $field_manager, TemporaryJsonapiFileFieldUploader $file_uploader, HttpKernelInterface $http_kernel)

Creates a new FileUpload instance.

Parameters

AccountInterface $current_user

The current user.

EntityFieldManagerInterface $field_manager

The entity field manager.

TemporaryJsonapiFileFieldUploader $file_uploader

The file uploader.

HttpKernelInterface $http_kernel

An HTTP kernel for making subrequests.

ResourceResponse handleFileUploadForExistingResource(Request $request, ResourceType $resource_type, string $file_field_name, FieldableEntityInterface $entity)

Handles JSON:API file upload requests.

Parameters

Request $request

The HTTP request object.

ResourceType $resource_type

The JSON:API resource type for the current request.

string $file_field_name

The file field for which the file is to be uploaded.

FieldableEntityInterface $entity

The entity for which the file is to be uploaded.

Return Value

ResourceResponse

The response object.

Exceptions

UnprocessableEntityHttpException
EntityStorageException
Exception

ResourceResponse handleFileUploadForNewResource(Request $request, ResourceType $resource_type, string $file_field_name)

Handles JSON:API file upload requests.

Parameters

Request $request

The HTTP request object.

ResourceType $resource_type

The JSON:API resource type for the current request.

string $file_field_name

The file field for which the file is to be uploaded.

Return Value

ResourceResponse

The response object.

Exceptions

UnprocessableEntityHttpException

static protected ensureFileUploadAccess(AccountInterface $account, FieldDefinitionInterface $field_definition, FieldableEntityInterface $entity = NULL)

Ensures that the given account is allowed to upload a file.

Parameters

AccountInterface $account

The account for which access should be checked.

FieldDefinitionInterface $field_definition

The field for which the file is to be uploaded.

FieldableEntityInterface $entity

The entity, if one exists, for which the file is to be uploaded.

protected FieldDefinitionInterface validateAndLoadFieldDefinition(string $entity_type_id, string $bundle, string $field_name)

Validates and loads a field definition instance.

Parameters

string $entity_type_id

The entity type ID the field is attached to.

string $bundle

The bundle the field is attached to.

string $field_name

The field name.

Return Value

FieldDefinitionInterface

The field definition.

Exceptions

NotFoundHttpException
AccessDeniedException