class Iso8601StringConstraintValidator in Duration Field 8.2
Same name and namespace in other branches
- 3.0.x src/Plugin/Validation/Constraint/Iso8601StringConstraintValidator.php \Drupal\duration_field\Plugin\Validation\Constraint\Iso8601StringConstraintValidator
Validates the iso_8601_string constraint.
Hierarchy
- class \Drupal\duration_field\Plugin\Validation\Constraint\Iso8601StringConstraintValidatorBase extends \Symfony\Component\Validator\ConstraintValidator
- class \Drupal\duration_field\Plugin\Validation\Constraint\Iso8601StringConstraintValidator
Expanded class hierarchy of Iso8601StringConstraintValidator
File
- src/
Plugin/ Validation/ Constraint/ Iso8601StringConstraintValidator.php, line 10
Namespace
Drupal\duration_field\Plugin\Validation\ConstraintView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Iso8601StringConstraintValidator:: |
public | function | Checks if the passed value is valid. | |
Iso8601StringConstraintValidatorBase:: |
protected | function | Test if a string is a valid ISO 8601 duration string. |