Return to Snippet

Revision: 2976
at May 19, 2007 07:18 by berkes


Initial Code
/**
 * Form alter hook Callbacks and helpers
 */
function _mymodule_formalter_exported_filter(&$form) {
  $filter_id = 'workflow_node.sid'; //set this to the id of the filter. use print_r($form['view'][#value']->filter) to find the ID

  foreach($form['view']['#value']->filter as $filter) {
    if ($filter['field'] == $filter_id) {
      $only_these = $filter['value'];
      break;
    }
  } 

  foreach ($form['filter0']['#options'] as $key => $option) {
    if (in_array($key, $only_these)) {
     $options[$key] = $option;
    }
  }
  $form['filter0']['#options'] = $options;

  if(is_array($form['filter0']['#default_value'])) {
    $form['filter0']['#default_value'] = 40; //or any other value.
  }
}

Initial URL


Initial Description
callback in a form alter to enforce an exposed filter to use only the options set in filter. Works for selectlists only.

Initial Title
Form alter to force exposed views filters to fllow filter options

Initial Tags
php, drupal

Initial Language
PHP