Change default '-Any-' in Drupal 7 exposed views dropdown selector filter

5.5k views Asked by At

I'd like to change the text of the default '-Any-' that Drupal 7 views uses for an exposed dropdown filter.

Based on an answer in this thread,

How to change the label of the default value (-Any-) of an exposed filter in Drupal Views?

I have created a module called any_exposed with a hook form alter:

function any_exposed_form_alter(&$form, &$form_state, $form_id) {
  if ($form['#id'] == 'views-exposed-form-vendors-page') {
$form['field_vendor_type_tid']['#options']['ALL'] = t('Everything'); } }

But all that does is add another option for 'Everything' in the dropdown, it does not overwrite/translate '-Any-'. Just to test I added:

$form['submit']['#value'] = t('Search');

Which changes the text of the Submit button from 'Apply' to 'Search', and this works fine. In case you can't tell, I'm not much of a programmer, but I figure I must be missing something simple. Any help would be appreciated!

4

There are 4 answers

0
wernerglinka On

This is an old post but in case you are still looking or for anybody who comes to this searching for an answer. 'ALL' must be 'All' as in

$form['field_vendor_type_tid']['#options']['All'] = t('Everything');

Since the array has a member 'All' but not 'ALL' (case is important here) you are adding a member 'ALL' while you want to overwrite 'All'.

0
Chandeep Khosa On

I recommend using Better Exposed Filters module, it allows you to do this simply via the Views UI interface.

  1. Install & enable the module
  2. Edit your view, then click on 'Exposed form > Exposed form style'
  3. Select 'Better Exposed Filters'
  4. Click 'More options'
  5. Change the value of 'Override "Any" option label'
1
Abhadiomhen stanley On
function any_exposed_form_alter(&$form, &$form_state, $form_id) {
  if ($form['#id'] == 'views-exposed-form-vendors-page') {
$form['field_vendor_type_tid']['#options']['ALL'] = t('Everything'); } } 

Works perfectly after changing ALL to All.

0
Rajesh Vishwakarma On

Use hook_form_views_exposed_form_alter instead hook_form_alter.

function hook_form_views_exposed_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'views_exposed_form') {
      $form['tid']['#options']['All'] = t('Search');
  }
}