You are here

protected function OptionsLimitWebformHandler::alterOptionsElement in Webform 6.x

Same name and namespace in other branches
  1. 8.5 modules/webform_options_limit/src/Plugin/WebformHandler/OptionsLimitWebformHandler.php \Drupal\webform_options_limit\Plugin\WebformHandler\OptionsLimitWebformHandler::alterOptionsElement()

Alter an options element.

Parameters

array $element: An options element with limits.

array $limits: An options element's option limits.

array $reached: An options element's reached options.

1 call to OptionsLimitWebformHandler::alterOptionsElement()
OptionsLimitWebformHandler::alterElement in modules/webform_options_limit/src/Plugin/WebformHandler/OptionsLimitWebformHandler.php
Alter webform element.

File

modules/webform_options_limit/src/Plugin/WebformHandler/OptionsLimitWebformHandler.php, line 621

Class

OptionsLimitWebformHandler
Webform options and boolean (boolean) limit handler.

Namespace

Drupal\webform_options_limit\Plugin\WebformHandler

Code

protected function alterOptionsElement(array &$element, array $limits, array $reached) {

  // Set options element's options labels.
  $options =& $element['#options'];
  $this
    ->alterOptionsElementLabels($options, $limits);

  // Disable or remove reached options.
  if ($reached) {
    switch ($this->configuration['option_none_action']) {
      case WebformOptionsLimitHandlerInterface::LIMIT_ACTION_DISABLE:
        $this
          ->disableOptionsElement($element, $reached);
        break;
      case WebformOptionsLimitHandlerInterface::LIMIT_ACTION_REMOVE:
        $this
          ->removeOptionsElement($element, $reached);
        break;
    }
  }

  // Display limit reached message.
  if (count($limits) === count($reached)) {
    $this
      ->setElementLimitReachedMessage($element);
  }
}