You are here

class DateRecurTimeZoneConstraintValidator in Recurring Dates Field 3.x

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

Validates the DateRecurTimeZone constraint.

Hierarchy

Expanded class hierarchy of DateRecurTimeZoneConstraintValidator

File

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

Namespace

Drupal\date_recur\Plugin\Validation\Constraint
View source
class DateRecurTimeZoneConstraintValidator extends ConstraintValidator {

  /**
   * {@inheritdoc}
   */
  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,
      ]);
    }
  }

}

Members