You are here

class DateRecurRruleConstraintValidator in Recurring Dates Field 8.2

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

Validates the DateRecurRruleConstraint constraint.

Hierarchy

Expanded class hierarchy of DateRecurRruleConstraintValidator

File

src/Plugin/Validation/Constraint/DateRecurRruleConstraintValidator.php, line 15

Namespace

Drupal\date_recur\Plugin\Validation\Constraint
View 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

Namesort descending Modifiers Type Description Overrides
DateRecurRruleConstraintValidator::validate public function Checks if the passed value is valid.