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!

4

4 に答える 4

4

これは古い投稿ですが、まだ探している場合、または答えを探している人のために. 'ALL' は 'All' でなければなりません。

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

配列にはメンバー 'All' がありますが 'ALL' はありません (ここでは大文字と小文字が重要です) ので、'All' を上書きしたいときにメンバー 'ALL' を追加しています。

于 2012-10-13T18:50:50.917 に答える
2

hook_form_alter の代わりに hook_form_views_exposed_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');
  }
}
于 2014-03-23T17:59:00.530 に答える