protected function TemporaryJsonapiFileFieldUploader::validate in JSON:API 8.2
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 src/
Controller/ TemporaryJsonapiFileFieldUploader.php - Creates and validates a file entity for a file field from a file stream.
File
- src/
Controller/ TemporaryJsonapiFileFieldUploader.php, line 363
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;
}