2

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!

Paul Roub
  • 36,322
  • 27
  • 84
  • 93
maskedjellybean
  • 689
  • 2
  • 9
  • 16

4 Answers4

4

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'.

2

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');
  }
}
0
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.

Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
  • Welcome to Stack Overflow! This doesn't seem to add anything to the earlier answer; if you were just saying thanks for that, please don't do that as an answer. Invest some time in the site and you will gain sufficient [privileges](http://stackoverflow.com/privileges) to upvote answers you like, which is the Stack Overflow way of saying thank you. – Nathan Tuggy Jan 20 '15 at 00:12
0

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'