public function CpfValueConstraintValidator::validate in CPF 8
Same name and namespace in other branches
- 8.2 src/Plugin/Validation/Constraint/CpfValueConstraintValidator.php \Drupal\cpf\Plugin\Validation\Constraint\CpfValueConstraintValidator::validate()
File
- src/
Plugin/ Validation/ Constraint/ CpfValueConstraintValidator.php, line 16
Class
- CpfValueConstraintValidator
- Validates that a field is a CPF number.
Namespace
Drupal\cpf\Plugin\Validation\ConstraintCode
public function validate($value, Constraint $constraint) {
// Verifica se o CPF é válido.
if (!\Drupal::service('cpf')
->isValid($value)) {
$this->context
->addViolation($constraint->message, [
'%value' => $value,
]);
}
}