get('entity')->getTarget()->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); } } } }