Make Drupal 6 View Filter Selection Match View Argument

Content

Make Drupal 6 View Filter Selection Match View Argument

Posted in:

The Issue here is that when filtering a Drupal 6 view using an argument the block filter selection does not match the argument.

View configuration

View accepts a single argument derived from a CCK field select list widget.
Filter is exposed as a block.
Filter block also includes the same CCK field as referenced in the argument.

In the snippet below 'field_make_value_many_to_one' is the name of the form select item that you want to match to your argument.

function mymodule_form_alter(&$form, $form_state, $form_id)
{
  // function seems to get called twice so need to cache
  static $term;
     
  switch($form_id) {
    
    // issue:
    // when filter view using argument the 
    //exposed filter block selection does not
    // match the argument
    //
    // we want to modify the form select element selection state
    case 'views_exposed_form':
      
      // take a peek
      // dvm($form_state['view'], 'hook_form_alter');

      // change the button text
      $form['submit']['#value'] = 'Search';

     // get the view argument if defined
     $term_arg = $form_state['view']->args[0];
     if (isset($term_arg)) {
       $term = $term_arg;
     }
     
     // change our input as required
     if (isset($term)) {
       $form_state['input']['field_make_value_many_to_one'] = $term;
     }
     break;
  }
}