You are here

public function RangeFromGreaterToConstraintValidator::validate in Range 8

File

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

Class

RangeFromGreaterToConstraintValidator
Validates the RangeFromGreaterTo constraint.

Namespace

Drupal\range\Plugin\Validation\Constraint

Code

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);
  }
}