aneuryzm
aneuryzm

Reputation: 64834

DRUPAL: order exposed filter items, be carefully it is not that simple (I cannot user "Sort")

DRUPAL question. I'm using Views, with an exposed filter (Taxonomy). I've downloaded the "better exposed filter" module to display it as checkbox list. a Now, how can I order the tags in the filter list ? "Views Sort" is not the solution because I only can order articles but not the filter items!!

I want to add an option (checkbox) for the customer to order the tags alphabetically or leave them in the default order.

thanks

Upvotes: 1

Views: 4047

Answers (1)

infojunkie
infojunkie

Reputation: 1090

You need to follow the example of Better Exposed Filters in form_alter'ing the exposed filters form and sorting your filter's #options array:

function mymodule_form_views_exposed_form_alter(&$form, $form_state) {
  foreach ($form_state['view']->filter as $field => $filter) {
    if ($filter->options['exposed'] /* && is my filter */) {
      $field_id = $form['#info']["filter-$field"]['value'];
      asort($form[$field_id]['#options']);
    }
  }
}

Upvotes: 2

Related Questions