You are here

class Iso8601StringConstraintValidator in Duration Field 8.2

Same name and namespace in other branches
  1. 3.0.x src/Plugin/Validation/Constraint/Iso8601StringConstraintValidator.php \Drupal\duration_field\Plugin\Validation\Constraint\Iso8601StringConstraintValidator

Validates the iso_8601_string constraint.

Hierarchy

Expanded class hierarchy of Iso8601StringConstraintValidator

File

src/Plugin/Validation/Constraint/Iso8601StringConstraintValidator.php, line 10

Namespace

Drupal\duration_field\Plugin\Validation\Constraint
View source
class Iso8601StringConstraintValidator extends Iso8601StringConstraintValidatorBase {

  /**
   * {@inheritdoc}
   */
  public function validate($items, Constraint $constraint) {
    if (is_array($items)) {
      foreach ($items as $item) {
        if (!$this
          ->isIso8601String($item)) {

          // The value is not a valid ISO 8601 duration string, so a violation,
          // aka error, is applied.
          $this->context
            ->addViolation($constraint->notIso8601, [
            '%value' => (string) $item,
          ]);
        }
      }
    }
    else {
      if (!$this
        ->isIso8601String($items)) {
        $this->context
          ->addViolation($constraint->notIso8601, [
          '%value' => (string) $items,
        ]);
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Iso8601StringConstraintValidator::validate public function Checks if the passed value is valid.
Iso8601StringConstraintValidatorBase::isIso8601String protected function Test if a string is a valid ISO 8601 duration string.