protected function TemporaryJsonapiFileFieldUploader::validate in Drupal 8
Same name and namespace in other branches
- 9 core/modules/jsonapi/src/Controller/TemporaryJsonapiFileFieldUploader.php \Drupal\jsonapi\Controller\TemporaryJsonapiFileFieldUploader::validate()
Validates the file.
Parameters
\Drupal\file\FileInterface $file: The file entity to validate.
array $validators: An array of upload validators to pass to file_validate().
Return value
\Drupal\Core\Entity\EntityConstraintViolationListInterface The list of constraint violations, if any.
1 call to TemporaryJsonapiFileFieldUploader::validate()
- TemporaryJsonapiFileFieldUploader::handleFileUploadForField in core/
modules/ jsonapi/ src/ Controller/ TemporaryJsonapiFileFieldUploader.php - Creates and validates a file entity for a file field from a file stream.
File
- core/
modules/ jsonapi/ src/ Controller/ TemporaryJsonapiFileFieldUploader.php, line 345
Class
- TemporaryJsonapiFileFieldUploader
- Reads data from an upload stream and creates a corresponding file entity.
Namespace
Drupal\jsonapi\ControllerCode
protected function validate(FileInterface $file, array $validators) {
$violations = $file
->validate();
// Remove violations of inaccessible fields as they cannot stem from our
// changes.
$violations
->filterByFieldAccess();
// Validate the file based on the field definition configuration.
$errors = file_validate($file, $validators);
if (!empty($errors)) {
$translator = new DrupalTranslator();
foreach ($errors as $error) {
$violation = new ConstraintViolation($translator
->trans($error), $error, [], EntityAdapter::createFromEntity($file), '', NULL);
$violations
->add($violation);
}
}
return $violations;
}