public function GranularityStringConstraintValidator::validate in Duration Field 3.0.x
Same name and namespace in other branches
- 8.2 src/Plugin/Validation/Constraint/GranularityStringConstraintValidator.php \Drupal\duration_field\Plugin\Validation\Constraint\GranularityStringConstraintValidator::validate()
File
- src/
Plugin/ Validation/ Constraint/ GranularityStringConstraintValidator.php, line 16
Class
- GranularityStringConstraintValidator
- Validates the granularity_string constraint.
Namespace
Drupal\duration_field\Plugin\Validation\ConstraintCode
public function validate($items, Constraint $constraint) {
if (is_array($items)) {
foreach ($items as $item) {
if (!$this
->isGranularityString($item)) {
// The value is not an integer, so a violation, aka error, is applied.
// The type of violation applied comes from the constraint description
// in step 1.
$this->context
->addViolation($constraint->notValidGranularityString, [
'%value' => (string) $item,
]);
}
}
}
else {
if (!$this
->isGranularityString($items)) {
$this->context
->addViolation($constraint->notValidGranularityString, [
'%value' => (string) $items,
]);
}
}
}