You are here

class TimeConstraintValidator 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

TimeConstraintValidator.

@package Drupal\time_field\Plugin\Validation\Constraint

Hierarchy

  • class \Drupal\time_field\Plugin\Validation\Constraint\TimeConstraintValidator extends \Symfony\Component\Validator\ConstraintValidator

Expanded class hierarchy of TimeConstraintValidator

File

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

Namespace

Drupal\time_field\Plugin\Validation\Constraint
View source
class TimeConstraintValidator extends ConstraintValidator {

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

}

Members

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