You are here

class IsbnConstraintValidator in ISBN Field 8

Hierarchy

  • class \Drupal\isbn\Plugin\Validation\Constraint\IsbnConstraintValidator extends \Symfony\Component\Validator\ConstraintValidator

Expanded class hierarchy of IsbnConstraintValidator

File

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

Namespace

Drupal\isbn\Plugin\Validation\Constraint
View source
class IsbnConstraintValidator extends ConstraintValidator {
  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,
        ]));
      }
    }
  }

}

Members