class RangeBothValuesRequiredConstraintValidator in Range 8
Validates the RangeBothValuesRequired constraint.
Hierarchy
- class \Drupal\range\Plugin\Validation\Constraint\RangeBothValuesRequiredConstraintValidator extends \Symfony\Component\Validator\ConstraintValidator
Expanded class hierarchy of RangeBothValuesRequiredConstraintValidator
1 file declares its use of RangeBothValuesRequiredConstraintValidator
- RangeBothValuesRequiredConstraintValidatorTest.php in tests/
src/ Unit/ Plugin/ Validation/ Constraint/ RangeBothValuesRequiredConstraintValidatorTest.php
File
- src/
Plugin/ Validation/ Constraint/ RangeBothValuesRequiredConstraintValidator.php, line 13
Namespace
Drupal\range\Plugin\Validation\ConstraintView source
class RangeBothValuesRequiredConstraintValidator extends ConstraintValidator {
/**
* {@inheritdoc}
*/
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);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RangeBothValuesRequiredConstraintValidator:: |
public | function | Checks if the passed value is valid. |