function CKEditor5ImageController::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 CKEditor5ImageController::validate()
- CKEditor5ImageController::upload in core/
modules/ ckeditor5/ src/ Controller/ CKEditor5ImageController.php - Uploads and saves an image from a CKEditor 5 POST.
File
-
core/
modules/ ckeditor5/ src/ Controller/ CKEditor5ImageController.php, line 239
Class
- CKEditor5ImageController
- Returns response for CKEditor 5 Simple image upload adapter.
Namespace
Drupal\ckeditor5\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), (string) $error, [], EntityAdapter::createFromEntity($file), '', NULL);
$violations->add($violation);
}
}
return $violations;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.