You are here

function theme_select_as_links in Better Exposed Filters 6

Same name and namespace in other branches
  1. 8.3 better_exposed_filters.theme \theme_select_as_links()
  2. 6.3 better_exposed_filters.theme \theme_select_as_links()
  3. 6.2 better_exposed_filters.theme \theme_select_as_links()
  4. 7.3 better_exposed_filters.theme \theme_select_as_links()
  5. 7 better_exposed_filters.theme \theme_select_as_links()

Themes a select drop-down as a collection of links

Parameters

object $element - An associative array containing the properties of the element.: Properties used: title, value, options, description, name

Return value

HTML string representing the form element.

See also

theme_select(), http://api.drupal.org/api/function/theme_select/6

1 string reference to 'theme_select_as_links'
better_exposed_filters_theme in ./better_exposed_filters.module
Implements hook_theme()

File

./better_exposed_filters.theme, line 304

Code

function theme_select_as_links($element) {
  $output = '';
  $name = $element['#name'];
  $selected_options = (array) $element['#post'][$name];

  // the selected keys from #options
  if (empty($_REQUEST[$name])) {
    $selected_options[] = $element["#{$name}"];
  }
  foreach ($element['#options'] as $option => $elem) {

    // Check for Taxonomy-based filters
    if (is_object($elem)) {
      list($option, $elem) = each(array_slice($elem->option, 0, 1, TRUE));
    }

    /*
     * Check for optgroups.  Put subelements in the $element_set array and add a group heading.
     * Otherwise, just add the element to the set
     */
    $element_set = array();
    if (is_array($elem)) {
      $element_set = $elem;
    }
    else {
      $element_set[$option] = $elem;
    }
    $links = array();
    $multiple = !empty($element['#multiple']);
    foreach ($element_set as $key => $value) {

      // Custom ID for each link based on the <select>'s original ID
      $id = form_clean_id($element['#id'] . '-' . $key);
      if (array_search($key, $selected_options) === FALSE) {
        $link = l($value, bef_replace_query_string_arg($name, $key, $multiple));
        $output .= theme('form_element', array(
          '#id' => $id,
        ), $link);
      }
      else {

        // Selected value is output without a link
        // TODO: Does that look funny in the display?  Should add a "current" class to this elem?
        $output .= theme('form_element', array(
          '#id' => $id,
        ), $value);
      }
    }
  }
  $properties = array(
    '#title' => $element['#title'],
    '#description' => $element['#description'],
  );
  return '<div class="bef-select-as-links">' . theme('form_element', $properties, $output) . '</div>';
}