You are here

public static function Registrants::validateRegistrantCount in RNG - Events and Registrations 3.x

Same name and namespace in other branches
  1. 8.2 src/Element/Registrants.php \Drupal\rng\Element\Registrants::validateRegistrantCount()
  2. 8 src/Element/Registrants.php \Drupal\rng\Element\Registrants::validateRegistrantCount()

Validate whether there are sufficient quantity of registrants.

File

src/Element/Registrants.php, line 756

Class

Registrants
Provides a form element for a registrant and person association.

Namespace

Drupal\rng\Element

Code

public static function validateRegistrantCount(&$element, FormStateInterface $form_state, &$complete_form) {

  /** @var \Drupal\rng\Entity\RegistrantInterface[] $registrants */
  $registrants = $element['#value'];
  $count = count($registrants);
  if (isset($element['#registrants_minimum'])) {
    $minimum = $element['#registrants_minimum'];
    if ($count < $minimum) {
      $form_state
        ->setError($element, t('There are not enough registrants on this registration. There must be at least @minimum registrants.', [
        '@minimum' => $minimum,
      ]));
    }
  }
  if (isset($element['#registrants_maximum'])) {
    $maximum = $element['#registrants_maximum'];
    if ($count > $maximum) {
      $form_state
        ->setError($element, t('There are too many registrants on this registration. There must be at most @maximum registrants.', [
        '@maximum' => $maximum,
      ]));
    }
  }
}