You are here

class QueueSizeConstraintValidator in Entityqueue 8

Validates the QueueSize constraint.

Hierarchy

  • class \Drupal\entityqueue\Plugin\Validation\Constraint\QueueSizeConstraintValidator extends \Symfony\Component\Validator\ConstraintValidator

Expanded class hierarchy of QueueSizeConstraintValidator

File

src/Plugin/Validation/Constraint/QueueSizeConstraintValidator.php, line 12

Namespace

Drupal\entityqueue\Plugin\Validation\Constraint
View source
class QueueSizeConstraintValidator extends ConstraintValidator {

  /**
   * {@inheritdoc}
   */
  public function validate($entity, Constraint $constraint) {
    assert($entity instanceof EntitySubqueueInterface);
    assert($constraint instanceof QueueSizeConstraint);
    $queue = $entity
      ->getQueue();
    $min_size = $queue
      ->getMinimumSize();
    $max_size = $queue
      ->getMaximumSize();
    $act_as_queue = $queue
      ->getActAsQueue();
    $number_of_items = count($entity->items);

    // Do not allow less items than the minimum size.
    if ($min_size && $number_of_items < $min_size) {
      $this->context
        ->buildViolation($constraint->messageMinSize, [
        '%min_size' => $min_size,
      ])
        ->addViolation();
    }
    elseif (!$act_as_queue && $max_size && $number_of_items > $max_size) {
      $this->context
        ->buildViolation($constraint->messageMaxSize, [
        '%max_size' => $max_size,
      ])
        ->addViolation();
    }
  }

}

Members

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