You are here

public function TimeConstraintValidator::validate in Time Field For Drupal 8.x / 9.x 8

Same name and namespace in other branches
  1. 2.x src/Plugin/Validation/Constraint/TimeConstraintValidator.php \Drupal\time_field\Plugin\Validation\Constraint\TimeConstraintValidator::validate()

File

src/Plugin/Validation/Constraint/TimeConstraintValidator.php, line 19

Class

TimeConstraintValidator
TimeConstraintValidator.

Namespace

Drupal\time_field\Plugin\Validation\Constraint

Code

public function validate($value, Constraint $constraint) {
  try {
    Time::createFromTimestamp($value);
  } catch (\InvalidArgumentException $e) {
    $this->context
      ->addViolation(TimeConstraint::$message, []);
  }
}