class FileValidationConstraintValidator in Drupal 10
Same name and namespace in other branches
- 8 core/modules/file/src/Plugin/Validation/Constraint/FileValidationConstraintValidator.php \Drupal\file\Plugin\Validation\Constraint\FileValidationConstraintValidator
- 9 core/modules/file/src/Plugin/Validation/Constraint/FileValidationConstraintValidator.php \Drupal\file\Plugin\Validation\Constraint\FileValidationConstraintValidator
Checks that a file referenced in a file field is valid.
Hierarchy
- class \Drupal\file\Plugin\Validation\Constraint\FileValidationConstraintValidator extends \Symfony\Component\Validator\ConstraintValidator
Expanded class hierarchy of FileValidationConstraintValidator
File
- core/
modules/ file/ src/ Plugin/ Validation/ Constraint/ FileValidationConstraintValidator.php, line 11
Namespace
Drupal\file\Plugin\Validation\ConstraintView source
class FileValidationConstraintValidator extends ConstraintValidator {
/**
* {@inheritdoc}
*/
public function validate($value, Constraint $constraint) {
// Get the file to execute validators.
$target = $value
->get('entity')
->getTarget();
if (!$target) {
return;
}
$file = $target
->getValue();
// Get the validators.
$validators = $value
->getUploadValidators();
// Checks that a file meets the criteria specified by the validators.
if ($errors = file_validate($file, $validators)) {
foreach ($errors as $error) {
$this->context
->addViolation($error);
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FileValidationConstraintValidator:: |
public | function |