DateRecurTimeZoneConstraintValidator.php in Recurring Dates Field 3.1.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;
class DateRecurTimeZoneConstraintValidator extends ConstraintValidator {
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,
]);
}
}
}