You are here

public function IsbnConstraintValidator::validate in ISBN Field 8

File

src/Plugin/Validation/Constraint/IsbnConstraintValidator.php, line 10

Class

IsbnConstraintValidator

Namespace

Drupal\isbn\Plugin\Validation\Constraint

Code

public function validate($value, Constraint $constraint) {
  if (gettype($value) == 'string') {
    $isbn_tools = \Drupal::service("isbn.isbn_service");
    if (!$isbn_tools
      ->isValidIsbn($value)) {
      $this->context
        ->addViolation(t('"%isbn" isn\'t a valid ISBN number.', [
        '%isbn' => $value,
      ]));
    }
  }
}