You are here

class RangeFromGreaterToConstraintValidator in Range 8

Validates the RangeFromGreaterTo constraint.

Hierarchy

Expanded class hierarchy of RangeFromGreaterToConstraintValidator

1 file declares its use of RangeFromGreaterToConstraintValidator
RangeFromGreaterToConstraintValidatorTest.php in tests/src/Unit/Plugin/Validation/Constraint/RangeFromGreaterToConstraintValidatorTest.php

File

src/Plugin/Validation/Constraint/RangeFromGreaterToConstraintValidator.php, line 13

Namespace

Drupal\range\Plugin\Validation\Constraint
View source
class RangeFromGreaterToConstraintValidator extends ConstraintValidator {

  /**
   * {@inheritdoc}
   */
  public function validate($value, Constraint $constraint) {
    if (!$value instanceof RangeItemInterface) {
      throw new UnexpectedTypeException($value, 'RangeItemInterface');
    }
    $range = $value
      ->getValue();
    if ($range['from'] > $range['to']) {
      $this->context
        ->addViolation($constraint->message);
    }
  }

}

Members

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