You are here

class CpfValueConstraintValidator in CPF 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Validation/Constraint/CpfValueConstraintValidator.php \Drupal\cpf\Plugin\Validation\Constraint\CpfValueConstraintValidator

Validates that a field is a CPF number.

Hierarchy

Expanded class hierarchy of CpfValueConstraintValidator

File

src/Plugin/Validation/Constraint/CpfValueConstraintValidator.php, line 11

Namespace

Drupal\cpf\Plugin\Validation\Constraint
View 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