class CpfValueConstraintValidator in CPF 8
Same name and namespace in other branches
- 8.2 src/Plugin/Validation/Constraint/CpfValueConstraintValidator.php \Drupal\cpf\Plugin\Validation\Constraint\CpfValueConstraintValidator
Validates that a field is a CPF number.
Hierarchy
- class \Drupal\cpf\Plugin\Validation\Constraint\CpfValueConstraintValidator extends \Symfony\Component\Validator\ConstraintValidator
Expanded class hierarchy of CpfValueConstraintValidator
File
- src/
Plugin/ Validation/ Constraint/ CpfValueConstraintValidator.php, line 11
Namespace
Drupal\cpf\Plugin\Validation\ConstraintView source
class CpfValueConstraintValidator extends ConstraintValidator {
/**
* {@inheritdoc}
*/
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,
]);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CpfValueConstraintValidator:: |
public | function |