public function DateRecurRruleConstraintValidator::validate in Recurring Dates Field 3.1.x
Same name and namespace in other branches
- 8.2 src/Plugin/Validation/Constraint/DateRecurRruleConstraintValidator.php \Drupal\date_recur\Plugin\Validation\Constraint\DateRecurRruleConstraintValidator::validate()
- 3.x src/Plugin/Validation/Constraint/DateRecurRruleConstraintValidator.php \Drupal\date_recur\Plugin\Validation\Constraint\DateRecurRruleConstraintValidator::validate()
- 3.0.x src/Plugin/Validation/Constraint/DateRecurRruleConstraintValidator.php \Drupal\date_recur\Plugin\Validation\Constraint\DateRecurRruleConstraintValidator::validate()
File
- src/
Plugin/ Validation/ Constraint/ DateRecurRruleConstraintValidator.php, line 20
Class
- DateRecurRruleConstraintValidator
- Validates the DateRecurRruleConstraint constraint.
Namespace
Drupal\date_recur\Plugin\Validation\ConstraintCode
public function validate($value, Constraint $constraint) : void {
assert($value instanceof DateRecurItem);
assert($constraint instanceof DateRecurRruleConstraint);
// Validator do not apply to field values without RRULE.
if (empty($value->rrule)) {
return;
}
try {
// Use a fake start time as there may be an empty or invalid start date.
DateRecurHelper::create($value->rrule, new \DateTime());
} catch (\Exception $e) {
$this->context
->addViolation($constraint->invalidRrule);
}
}