Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I have an exposed taxonomy filter that allows the user the filter by term. The vocabulary is 2 tiers, however in the exposed filter menu the hierarchy appears flat.

Is there a method/module to show the hierarchy with indentation or prefixing child terms with "-", similar to the taxonomy term selection menu from the node edit form itself.

x-post from http://stackoverflow.com/questions/6222875/drupal-views-taxonomy-exposed-filter-show-tree-hierarchy-in-drop-down-menu

SOLUTION:

The filter Taxonomy: Term ID (with Depth) will display the option "Show Hierarchy In Dropdown" when you select the Dropdown widget.

share|improve this question

2 Answers 2

up vote 3 down vote accepted

The filter Taxonomy: Term ID (with Depth) will display the option "Show Hierarchy In Dropdown" when you select the Dropdown widget.

share|improve this answer
<?php
/**
 * Implementing hook_form_alter()
 * @param $form
 * @param $form_state
 * @param $form_id
 */
function YOUR_MODULE_NAME_form_alter(&$form, $form_state, $form_id) {
    if ($form_id == 'views_exposed_form') {
        $term_reference_tree_path = drupal_get_path('module', 'term_reference_tree');
        // You should give , your exposed taxonomy field
        $form['your-toxonomy-field'] = array(
            //s'#title' => t('Tree'),
            '#type' => 'checkbox_tree',
            '#max_choices' => 999,
            '#max_depth' => 999,
            '#field_name' => 'custom_name',
            // '#leaves_only' => 1,
            '#start_minimized' => TRUE,
            '#depth' => 0,
            '#vocabulary' => taxonomy_vocabulary_load(3), // instead of '3', Your vocabulary term ID 
            '#parent_tid' => 0,
            '#value_key' => 'tid',
            '#select_parents' => TRUE,
            '#attached' => array(
                'js' => array($term_reference_tree_path . '/term_reference_tree.js'),
                'css' => array($term_reference_tree_path . '/term_reference_tree.css')
            ),
            '#attributes' => array('class' => array('field-widget-term-reference-tree')),
            '#element_validate' => array('_term_reference_tree_widget_validate'),
            '#value' => array(),
            '#filter_view' => '',
            '#token_display' => ''
        );
    }

}

Please check this

http://worldofdrupal.blogspot.in/2015/06/views-exposed-taxonomy-exposed-filter.html

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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