0

I've made a view with an exposed filter. This filter is taxonomy based, and I'm using Hierarchical Select as the widget because this taxonomy is deeply nested.

This question is greatly similar to: How to change the label of the default value (-Any-) of an exposed filter in Drupal Views?

However, the poster of that question was not using HS, and so I cannot use the answers there, specifically this one: https://stackoverflow.com/a/5975294/443219

Where exactly should I place the '#options' key in the $form array when using hook_form_alter, to make this work? I've tried pasting the relevant line of code blindly in different places throughout the array, but I believe HS works a tad different to FAPI...

Community
  • 1
  • 1
Aditya M P
  • 4,493
  • 6
  • 33
  • 69

2 Answers2

0

You can use following code any drupal module. this will work.

/**
 * hook_views_pre_view
 * @param type $view
 * @param type $display_id
 * @param type $args
 */
function MODULE_NAME_views_pre_view(&$view, &$display_id, &$args) {
  if ($view->name == 'VIEW_NAME') {
    $filters = $view->display_handler->get_option('filters');    
    $view->display_handler->override_option('filters', $filters);
  }
}



/**
 * hook__views_pre_build
 * @param type $view
 * @return type
 */
function MODULE_NAME_views_pre_build($view) { 
  if ($view->name=='VIEW_NAME') {    
    $view->display['page']->handler->handlers['filter']['filter_field']->value['value'] = 8;
    return $view;
  }     
}
purab
  • 213
  • 1
  • 3
  • 9
  • Thanks for the answer... but the problem is very old now and I don't want to go back to it right now. Some other soul might need it, test it, and let you know if it's any good... – Aditya M P Aug 05 '13 at 12:11
0

I have a horrible answer to this.

I changed line 402 in sites/all/modules/hierarchical_select/hs_taxonomy_views.module from:

$any_label = variable_get('views_exposed_filter_any_label', 'old_any') === 'old_any' ? '<'. t('Any') .'>' : '- '. t('Any') .' -';

to

$any_label = variable_get('views_exposed_filter_any_label', 'old_any') === 'old_any' ? 'Worldwide' : '- '. t('Any') .' -';

This works because: in this site, I need the filter on only view - and nowhere else.

This can never be a general solution because:

  1. The unholy sin of hacking the core of a module will haunt me forever because I cannot ever use drush to update this module again.
  2. If I ever make another view in this site, and decide to have a hs taxonomy exposed filter, it's "Any" option will be displayed as "Worldwide", even if there is no such context: weird.

I would greatly appreciate if anyone can point me in a direction that will allow me to solve this cleanly. But I'm going with my hack for now.

Aditya M P
  • 4,493
  • 6
  • 33
  • 69