You are here

function webform_preprocess_select in Webform 6.x

Same name and namespace in other branches
  1. 8.5 includes/webform.theme.inc \webform_preprocess_select()

Implements hook_preprocess_select() for select templates.

File

includes/webform.theme.inc, line 298
Theme hooks, preprocessor, and suggestions.

Code

function webform_preprocess_select(&$variables) {
  if (!WebformElementHelper::isWebformElement($variables['element'])) {
    return;
  }
  $element = $variables['element'];

  // When options are sorted (viu #sort_options: true) make sure the
  // select '_other_' options is always last.
  // @see \Drupal\webform\Element\WebformOtherBase::processWebformOther
  // @see template_preprocess_select().
  if (!empty($element['#sort_options']) && !empty($element['#webform_other'])) {
    $options =& $variables['options'];
    foreach ($options as $index => $option) {
      if ($option['value'] === WebformSelectOther::OTHER_OPTION) {
        unset($options[$index]);
        $options[] = $option;
        $options = array_values($options);
        break;
      }
    }
  }
}