You are here

class MinQtyLessThanOrEqualMaxQtyConstraintValidator in Commerce Product Bundle 8

Validates the MinQtyLessThanOrEqualMaxQty constraint.

Hierarchy

Expanded class hierarchy of MinQtyLessThanOrEqualMaxQtyConstraintValidator

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

File

src/Plugin/Validation/Constraint/MinQtyLessThanOrEqualMaxQtyConstraintValidator.php, line 11

Namespace

Drupal\commerce_product_bundle\Plugin\Validation\Constraint
View source
class MinQtyLessThanOrEqualMaxQtyConstraintValidator extends ConstraintValidator {

  /**
   * @inheritdoc
   */
  public function validate($entity, Constraint $constraint) {
    if (!isset($entity)) {
      return;
    }
    $max = $entity
      ->getMaximumQuantity();
    $min = $entity
      ->getMinimumQuantity();
    if ($min > $max) {
      $this->context
        ->buildViolation($constraint->message)
        ->setParameter('%min', $min)
        ->setParameter('%max', $max)
        ->addViolation();
    }
  }

}

Members