public static function TemporaryJsonapiFileFieldUploader::checkFileUploadAccess in Drupal 8
Same name and namespace in other branches
- 9 core/modules/jsonapi/src/Controller/TemporaryJsonapiFileFieldUploader.php \Drupal\jsonapi\Controller\TemporaryJsonapiFileFieldUploader::checkFileUploadAccess()
- 10 core/modules/jsonapi/src/Controller/TemporaryJsonapiFileFieldUploader.php \Drupal\jsonapi\Controller\TemporaryJsonapiFileFieldUploader::checkFileUploadAccess()
Checks if the current user has access to upload the file.
Parameters
\Drupal\Core\Session\AccountInterface $account: The account for which file upload access should be checked.
\Drupal\Core\Field\FieldDefinitionInterface $field_definition: The field definition for which to get validators.
\Drupal\Core\Entity\EntityInterface $entity: (optional) The entity to which the file is to be uploaded, if it exists. If the entity does not exist and it is not given, create access to the file will be checked.
Return value
\Drupal\Core\Access\AccessResultInterface The file upload access result.
1 call to TemporaryJsonapiFileFieldUploader::checkFileUploadAccess()
- FileUpload::ensureFileUploadAccess in core/
modules/ jsonapi/ src/ Controller/ FileUpload.php - Ensures that the given account is allowed to upload a file.
File
- core/
modules/ jsonapi/ src/ Controller/ TemporaryJsonapiFileFieldUploader.php, line 263
Class
- TemporaryJsonapiFileFieldUploader
- Reads data from an upload stream and creates a corresponding file entity.
Namespace
Drupal\jsonapi\ControllerCode
public static function checkFileUploadAccess(AccountInterface $account, FieldDefinitionInterface $field_definition, EntityInterface $entity = NULL) {
assert(is_null($entity) || $field_definition
->getTargetEntityTypeId() === $entity
->getEntityTypeId() && $field_definition
->getTargetBundle() === $entity
->bundle());
$entity_type_manager = \Drupal::entityTypeManager();
$entity_access_control_handler = $entity_type_manager
->getAccessControlHandler($field_definition
->getTargetEntityTypeId());
$bundle = $entity_type_manager
->getDefinition($field_definition
->getTargetEntityTypeId())
->hasKey('bundle') ? $field_definition
->getTargetBundle() : NULL;
$entity_access_result = $entity ? $entity_access_control_handler
->access($entity, 'update', $account, TRUE) : $entity_access_control_handler
->createAccess($bundle, $account, [], TRUE);
$field_access_result = $entity_access_control_handler
->fieldAccess('edit', $field_definition, NULL, NULL, TRUE);
return $entity_access_result
->andIf($field_access_result);
}