You are here

public function NifValueValidator::validate in Field NIF 8

File

src/Plugin/Validation/Constraint/NifValueValidator.php, line 17

Class

NifValueValidator
Validates a NIF/CIF/NIE document number.

Namespace

Drupal\field_nif\Plugin\Validation\Constraint

Code

public function validate($value, Constraint $constraint) {
  $document_value = NifUtils::validateNifCifNie($value, $constraint
    ->getSupportedTypes());
  if (!$document_value) {
    $this->context
      ->addViolation($constraint
      ->getMessage(), [
      '@value' => $value,
      '@document_type' => empty($constraint
        ->getSupportedTypes()) ? 'NIF/CIF/NIE' : mb_strtoupper(implode('/', $constraint
        ->getSupportedTypes())),
    ]);
  }
}