class DateRecurRruleConstraintValidator in Recurring Dates Field 8.2
Same name and namespace in other branches
- 3.x src/Plugin/Validation/Constraint/DateRecurRruleConstraintValidator.php \Drupal\date_recur\Plugin\Validation\Constraint\DateRecurRruleConstraintValidator
- 3.0.x src/Plugin/Validation/Constraint/DateRecurRruleConstraintValidator.php \Drupal\date_recur\Plugin\Validation\Constraint\DateRecurRruleConstraintValidator
- 3.1.x src/Plugin/Validation/Constraint/DateRecurRruleConstraintValidator.php \Drupal\date_recur\Plugin\Validation\Constraint\DateRecurRruleConstraintValidator
Validates the DateRecurRruleConstraint constraint.
Hierarchy
- class \Drupal\date_recur\Plugin\Validation\Constraint\DateRecurRruleConstraintValidator extends \Symfony\Component\Validator\ConstraintValidator
Expanded class hierarchy of DateRecurRruleConstraintValidator
File
- src/
Plugin/ Validation/ Constraint/ DateRecurRruleConstraintValidator.php, line 15
Namespace
Drupal\date_recur\Plugin\Validation\ConstraintView source
class DateRecurRruleConstraintValidator extends ConstraintValidator {
/**
* {@inheritdoc}
*/
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);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DateRecurRruleConstraintValidator:: |
public | function | Checks if the passed value is valid. |