protected function FileUploadResource::validate in Drupal 8
Same name and namespace in other branches
- 9 core/modules/file/src/Plugin/rest/resource/FileUploadResource.php \Drupal\file\Plugin\rest\resource\FileUploadResource::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().
Throws
\Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException Thrown when there are file validation errors.
1 call to FileUploadResource::validate()
- FileUploadResource::post in core/
modules/ file/ src/ Plugin/ rest/ resource/ FileUploadResource.php - Creates a file from an endpoint.
File
- core/
modules/ file/ src/ Plugin/ rest/ resource/ FileUploadResource.php, line 437
Class
- FileUploadResource
- File upload resource.
Namespace
Drupal\file\Plugin\rest\resourceCode
protected function validate(FileInterface $file, array $validators) {
$this
->resourceValidate($file);
// Validate the file based on the field definition configuration.
$errors = file_validate($file, $validators);
if (!empty($errors)) {
$message = "Unprocessable Entity: file validation failed.\n";
$message .= implode("\n", array_map(function ($error) {
return PlainTextOutput::renderFromHtml($error);
}, $errors));
throw new UnprocessableEntityHttpException($message);
}
}