You are here

protected function OptionsLimitWebformHandler::alterOptionsElementLabels in Webform 8.5

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

Alter an options element's option labels recursively.

Parameters

array $options: An options element with limits.

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

1 call to OptionsLimitWebformHandler::alterOptionsElementLabels()
OptionsLimitWebformHandler::alterOptionsElement in modules/webform_options_limit/src/Plugin/WebformHandler/OptionsLimitWebformHandler.php
Alter an options element.

File

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

Class

OptionsLimitWebformHandler
Webform options and boolean (boolean) limit handler.

Namespace

Drupal\webform_options_limit\Plugin\WebformHandler

Code

protected function alterOptionsElementLabels(array &$options, array $limits) {
  $message_display = $this->configuration['option_message_display'];
  foreach ($options as $option_value => $option_text) {
    if ($this
      ->isTableSelectElement()) {
      if (isset($limits[$option_value])) {
        $label = $this
          ->getOptionsLimitLabel($option_text[0]['value'], $limits[$option_value]);
        $message_display = $this->configuration['option_message_display'];
        $option =& $options[$option_value][0];
        switch ($message_display) {
          case WebformOptionsLimitHandlerInterface::MESSAGE_DISPLAY_DESCRIPTION:
            list($option['value'], $option['webform_options_limit']) = explode(' --', $label);
            break;
          case WebformOptionsLimitHandlerInterface::MESSAGE_DISPLAY_LABEL:
            $option['value'] = $label;
            break;
        }
      }
    }
    elseif (is_array($option_text)) {
      $this
        ->alterOptionsElementLabels($option_text, $limits);
    }
    elseif (isset($limits[$option_value])) {
      $options[$option_value] = $this
        ->getOptionsLimitLabel($option_text, $limits[$option_value]);
    }
  }
}