function FileUploadResource::validate
Same name in other branches
- 8.9.x core/modules/file/src/Plugin/rest/resource/FileUploadResource.php \Drupal\file\Plugin\rest\resource\FileUploadResource::validate()
Validates the file.
@todo this method is unused in this class because file validation needs to be split up in 2 steps in ::post(). Add a deprecation notice as soon as a central core file upload service can be used in this class. See https://www.drupal.org/project/drupal/issues/2940383
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.
File
-
core/
modules/ file/ src/ Plugin/ rest/ resource/ FileUploadResource.php, line 481
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);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.