You are here

public function DateRecurTimeZoneConstraintValidator::validate in Recurring Dates Field 8.2

Same name and namespace in other branches
  1. 3.x src/Plugin/Validation/Constraint/DateRecurTimeZoneConstraintValidator.php \Drupal\date_recur\Plugin\Validation\Constraint\DateRecurTimeZoneConstraintValidator::validate()
  2. 3.0.x src/Plugin/Validation/Constraint/DateRecurTimeZoneConstraintValidator.php \Drupal\date_recur\Plugin\Validation\Constraint\DateRecurTimeZoneConstraintValidator::validate()
  3. 3.1.x src/Plugin/Validation/Constraint/DateRecurTimeZoneConstraintValidator.php \Drupal\date_recur\Plugin\Validation\Constraint\DateRecurTimeZoneConstraintValidator::validate()

File

src/Plugin/Validation/Constraint/DateRecurTimeZoneConstraintValidator.php, line 18

Class

DateRecurTimeZoneConstraintValidator
Validates the DateRecurTimeZone constraint.

Namespace

Drupal\date_recur\Plugin\Validation\Constraint

Code

public function validate($value, Constraint $constraint) {
  assert($constraint instanceof DateRecurTimeZoneConstraint);
  $timeZones = \DateTimeZone::listIdentifiers();
  if (is_string($value) && !in_array($value, $timeZones)) {
    $this->context
      ->addViolation($constraint->invalidTimeZone, [
      '%value' => $value,
    ]);
  }
}