2

In drupal 7, I'm trying to remove an exposed taxonomy filter. This taxonomy filter has a depth of 2. I'm only trying to expose the parent item.

As a quick fix I'm trying (poorly) to remove them with the following theme function below.

<?php
function theme_preprocess_views_exposed_form(&$vars, $hook) {

    //  views-exposed-form-instructor-profile-list-page
    switch($vars['form']['#id']) {

        // instructor profile       
        case 'views-exposed-form-instructor-profile-list-page':
            foreach ($vars['form']['term_node_tid_depth']['#options'] as $option) { 
                foreach ($option->option as $key=>$v) {
                        if (stristr($v, '-')) {
                            print $v . '<br>';
                            $vars['form']['term_node_tid_depth']['#options']['option'][$key] = 'FILTERED';
                        }
                }
            }           

            print_r($vars['form']['term_node_tid_depth']['#options']['option']);
            break;

        // do nothing
        default:



    }
}

In the end I'm trying to figure out what exactly to unset() any option that begins with '- child item'.

3

Instead try the following it will help you by using hook_form_alter()

function mymodule_form_views_exposed_form_alter(&$form, &$form_state, $form_id) {

  if($form['#id'] == 'views-exposed-form-[your-view-here]') {

    foreach ($form['tid']['#options'] as $term_key => $term) {

      // Check if this isn't the 'ANY' option
      if($term_key !== 'All') {
        // Check if this is a child by looking for '-' as first char in string
        $term_value = reset($term->option);
        if($term_value[0] == '-') {
          unset($form['tid']['#options'][$term_key]);
        }
      }

    }

  }

}

taken from the source

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.