You are here

class NifValueValidator in Field NIF 8

Validates a NIF/CIF/NIE document number.

Hierarchy

  • class \Drupal\field_nif\Plugin\Validation\Constraint\NifValueValidator extends \Symfony\Component\Validator\ConstraintValidator

Expanded class hierarchy of NifValueValidator

File

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

Namespace

Drupal\field_nif\Plugin\Validation\Constraint
View source
class NifValueValidator extends ConstraintValidator {

  /**
   * {@inheritdoc}
   */
  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())),
      ]);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
NifValueValidator::validate public function Checks if the passed value is valid.