You are here

class RangeBothValuesRequiredConstraintValidator in Range 8

Validates the RangeBothValuesRequired constraint.

Hierarchy

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\Constraint
View 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

Namesort descending Modifiers Type Description Overrides
RangeBothValuesRequiredConstraintValidator::validate public function Checks if the passed value is valid.