public function RangeBothValuesRequiredConstraintValidator::validate in Range 8
File
- src/
Plugin/ Validation/ Constraint/ RangeBothValuesRequiredConstraintValidator.php, line 18
Class
- RangeBothValuesRequiredConstraintValidator
- Validates the RangeBothValuesRequired constraint.
Namespace
Drupal\range\Plugin\Validation\ConstraintCode
public function validate($value, Constraint $constraint) {
if (!$value instanceof RangeItemInterface) {
throw new UnexpectedTypeException($value, 'RangeItemInterface');
}
$range = $value
->getValue();
if (empty($range['from']) && (string) $range['from'] !== '0' || empty($range['to']) && (string) $range['to'] !== '0') {
$this->context
->addViolation($constraint->message);
}
}