You are here

function jump_menu_form_select_options in Better Jump Menus 7

Same name and namespace in other branches
  1. 8 jump_menu.module \jump_menu_form_select_options()

Provide alternate select options builder. Taken from form_select_options() within includes/form.inc

1 call to jump_menu_form_select_options()
jump_menu_select in ./jump_menu.module
Override select theme function (points select theming to following function).

File

./jump_menu.module, line 370
Make use of the CTools jump menu and grabs from an existing menu. See: modules/ctools/includes/jump-menu.inc NOTE: Menu items must be checked as "expanded" for traversing to work.

Code

function jump_menu_form_select_options($element, $choices = NULL) {
  if (!isset($choices)) {
    $choices = $element['#options'];
  }

  // Using array_key_exists() accommodates the rare event where $element['#value'] is NULL.
  // Note that isset() fails in this situation.
  $value_valid = isset($element['#value']) || array_key_exists('#value', $element);
  $value_is_array = $value_valid && is_array($element['#value']);
  $options = '';
  foreach ($choices as $key => $choice) {

    // Allow overloading options with an array.
    if (is_array($choice)) {
      if (isset($choice['value'])) {

        // Overloaded option array.
        $opt_value = (string) $choice['value'];
      }
      else {
        if (isset($choice['title'])) {

          // Optgroup for special menu items.
          $options .= '<optgroup label="' . $choice['title'] . '"></optgroup>';
        }
        else {

          // Normal optgroups.
          $options .= '<optgroup label="' . $key . '">';
          $options .= form_select_options($element, $choice);
          $options .= '</optgroup>';
        }
      }
    }
    else {

      // Simple options.
      $opt_value = $key;
      $choice = array(
        'title' => $choice,
      );
    }

    // Create the HTML output.
    if (isset($opt_value)) {
      if (!isset($choice['#attributes'])) {
        $choice['#attributes'] = array();
      }

      // Note this makes the first item no longer selected, but that doesn't matter.
      if ($value_valid && (!$value_is_array && (string) $element['#value'] === $opt_value || $value_is_array && in_array($opt_value, $element['#value']))) {
        $selected = ' selected="selected"';
      }
      else {
        $selected = '';
      }
      $options .= '<option value="' . check_plain($opt_value) . '"' . $selected . drupal_attributes($choice['#attributes']) . '>' . check_plain($choice['title']) . '</option>';
    }
    unset($opt_value);
  }
  return $options;
}