You are here

DateRecurTimeZoneConstraintValidator.php in Recurring Dates Field 3.x

File

src/Plugin/Validation/Constraint/DateRecurTimeZoneConstraintValidator.php
View source
<?php

declare (strict_types=1);
namespace Drupal\date_recur\Plugin\Validation\Constraint;

use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;

/**
 * Validates the DateRecurTimeZone constraint.
 */
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,
      ]);
    }
  }

}

Classes

Namesort descending Description
DateRecurTimeZoneConstraintValidator Validates the DateRecurTimeZone constraint.