FileValidationConstraintValidator.php in Drupal 9
File
core/modules/file/src/Plugin/Validation/Constraint/FileValidationConstraintValidator.php
View source
<?php
namespace Drupal\file\Plugin\Validation\Constraint;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
class FileValidationConstraintValidator extends ConstraintValidator {
public function validate($value, Constraint $constraint) {
$target = $value
->get('entity')
->getTarget();
if (!$target) {
return;
}
$file = $target
->getValue();
$validators = $value
->getUploadValidators();
if ($errors = file_validate($file, $validators)) {
foreach ($errors as $error) {
$this->context
->addViolation($error);
}
}
}
}