function FileIsImageConstraintValidator::validate
File
- 
              core/
modules/ file/ src/ Plugin/ Validation/ Constraint/ FileIsImageConstraintValidator.php, line 38  
Class
- FileIsImageConstraintValidator
 - Validator for the FileIsImageConstraint.
 
Namespace
Drupal\file\Plugin\Validation\ConstraintCode
public function validate(mixed $value, Constraint $constraint) {
  $file = $this->assertValueIsFile($value);
  if (!$constraint instanceof FileIsImageConstraint) {
    throw new UnexpectedTypeException($constraint, FileIsImageConstraint::class);
  }
  $image = $this->imageFactory
    ->get($file->getFileUri());
  if (!$image->isValid()) {
    $supportedExtensions = $this->imageFactory
      ->getSupportedExtensions();
    $this->context
      ->addViolation($constraint->message, [
      '%types' => implode(', ', $supportedExtensions),
    ]);
  }
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.