当前位置: 动力学知识库 > 问答 > 编程问答 >

Drupal: how to make select list show taxonomy terms in hierarchy?

问题描述:

I have a block generated by Finder module (simple search mechanism). The block contains a form with select lists of various taxonomy dictionaries.

Their order, however seems quite random (neither, alphabetical, nor chronological) and lists regions in such an order with no hierarchy:

Italy, France, Poland, Benelux, ..., Upper Austria, ... Switzerland, Tyrol, Croatia

alt text http://i42.tinypic.com/24owysj.jpg

The order I expect is my dictionary hierarchy, so:

Austria, Austria>Tyrol, Austria>Upper Austria, Benelux, Croatia, France, Italy, Poland, Switzerland

Do You have any idea how to make the select list items appear in the dictionary hierarchy order?


Edit: Finder configuration:

array(

'finder_id' => '5',

'base' => 'views',

'title' => 'Search results',

'description' => 'Finder for search',

'path' => 'search',

'block' => '1',

'settings' => array(

'form_on_page' => 0,

'form' => array(

'prefix' => '',

'prefix_format' => '2',

'suffix' => '',

'suffix_format' => '2',

'button_text' => 'Find',

'go_text' => 'Go',

),

'advanced' => array(

'no_results' => array(

'no_results' => 'We can\'t find any tours. Try to search for other tours.',

),

'filter' => 1,

'submission' => 1,

'ahah' => 0,

'ahah_effect' => 'fade',

'element_combination' => '2',

'pager' => '0',

'match' => 'c',

'goto' => '',

'hide_args' => 1,

'arg_sep' => ',',

'empty_symbol' => '',

'show_links' => 1,

'show_admin_links' => 0,

'cache_finder_find' => '360',

'search' => '0',

'search_tab' => 'node',

),

'views' => array(

'view' => 'search_start',

'displays' => array(

'query' => 'default',

'output' => 'default',

),

'results' => '0',

'views_args' => array(

'args' => '',

'delimiter' => '/',

),

),

'i18nstrings' => array(

'title' => array(

'#i18nstrings' => 'finder:f5:title',

),

'description' => array(

'#i18nstrings' => 'finder:f5:description',

),

'settings' => array(

'form' => array(

'prefix' => array(

'#i18nstrings' => 'finder:f5:settings][form][prefix',

),

'suffix' => array(

'#i18nstrings' => 'finder:f5:settings][form][suffix',

),

'button_text' => array(

'#i18nstrings' => 'finder:f5:settings][form][button_text',

),

'go_text' => array(

'#i18nstrings' => 'finder:f5:settings][form][go_text',

),

),

'advanced' => array(

'no_results' => array(

'no_results' => array(

'#i18nstrings' => 'finder:f5:settings][advanced][no_results][no_results',

),

),

'pager' => array(

'#i18nstrings' => 'finder:f5:settings][advanced][pager',

),

'arg_sep' => array(

'#i18nstrings' => 'finder:f5:settings][advanced][arg_sep',

),

'empty_symbol' => array(

'#i18nstrings' => 'finder:f5:settings][advanced][empty_symbol',

),

'cache_finder_find' => array(

'#i18nstrings' => 'finder:f5:settings][advanced][cache_finder_find',

),

),

),

),

),

'elements' => array(

'0' => array(

'finder_element_id' => '13',

'finder_id' => '5',

'element' => 'select',

'title' => 'Region',

'weight' => '0',

'settings' => array(

'form' => array(

'description' => '',

'prefix' => '',

'prefix_format' => '2',

'suffix' => '',

'suffix_format' => '2',

'default_value' => '',

'required' => 0,

'size' => '',

'multiple' => 0,

'empty' => 'prepend',

'empty_text' => '- every region -',

),

'choices' => array(

'field' => array(

'term_data_1.name' => 'term_data_1.name',

),

'rewrite' => array(

'php' => '',

),

'displays' => array(

'query' => 'default',

),

'views' => array(

'args' => '',

'delimiter' => '/',

),

),

'advanced' => array(

'delimit' => '',

'value_combination' => '0',

),

'i18nstrings' => array(

'title' => array(

'#i18nstrings' => 'finder:e13:title',

),

'settings' => array(

'form' => array(

'description' => array(

'#i18nstrings' => 'finder:e13:settings][form][description',

),

'prefix' => array(

'#i18nstrings' => 'finder:e13:settings][form][prefix',

),

'suffix' => array(

'#i18nstrings' => 'finder:e13:settings][form][suffix',

),

'default_value' => array(

'#i18nstrings' => 'finder:e13:settings][form][default_value',

),

),

'advanced' => array(

'delimit' => array(

'#i18nstrings' => 'finder:e13:settings][advanced][delimit',

),

),

),

),

),

'element_handler' => array(

'#title' => 'Select list',

'#module' => 'finder_optionwidgets',

),

'#_finder_object' => '1',

),

'1' => array(

'finder_element_id' => '14',

'finder_id' => '5',

'element' => 'select',

'title' => 'Season',

'weight' => '1',

'settings' => array(

'form' => array(

'description' => '',

'prefix' => '',

'prefix_format' => '2',

'suffix' => '',

'suffix_format' => '2',

'default_value' => '',

'required' => 0,

'size' => '',

'multiple' => 0,

'empty' => 'prepend',

'empty_text' => '- every season -',

),

'choices' => array(

'field' => array(

'term_data_2.name' => 'term_data_2.name',

),

'rewrite' => array(

'php' => '',

),

'displays' => array(

'query' => 'default',

),

'views' => array(

'args' => '',

'delimiter' => '/',

),

),

'advanced' => array(

'delimit' => '',

'value_combination' => '0',

),

'i18nstrings' => array(

'title' => array(

'#i18nstrings' => 'finder:e14:title',

),

'settings' => array(

'form' => array(

'description' => array(

'#i18nstrings' => 'finder:e14:settings][form][description',

),

'prefix' => array(

'#i18nstrings' => 'finder:e14:settings][form][prefix',

),

'suffix' => array(

'#i18nstrings' => 'finder:e14:settings][form][suffix',

),

'default_value' => array(

'#i18nstrings' => 'finder:e14:settings][form][default_value',

),

),

'advanced' => array(

'delimit' => array(

'#i18nstrings' => 'finder:e14:settings][advanced][delimit',

),

),

),

),

),

'element_handler' => array(

'#title' => 'Select list',

'#module' => 'finder_optionwidgets',

),

'#_finder_object' => '1',

),

'2' => array(

'finder_element_id' => '15',

'finder_id' => '5',

'element' => 'select',

'title' => 'Theme',

'weight' => '2',

'settings' => array(

'form' => array(

'description' => '',

'prefix' => '',

'prefix_format' => '2',

'suffix' => '',

'suffix_format' => '2',

'default_value' => '',

'required' => 0,

'size' => '',

'multiple' => 0,

'empty' => 'prepend',

'empty_text' => '- every theme -',

),

'choices' => array(

'field' => array(

'term_data_3.name' => 'term_data_3.name',

),

'rewrite' => array(

'php' => '',

),

'displays' => array(

'query' => 'default',

),

'views' => array(

'args' => '',

'delimiter' => '/',

),

),

'advanced' => array(

'delimit' => '',

'value_combination' => '0',

),

'i18nstrings' => array(

'title' => array(

'#i18nstrings' => 'finder:e15:title',

),

'settings' => array(

'form' => array(

'description' => array(

'#i18nstrings' => 'finder:e15:settings][form][description',

),

'prefix' => array(

'#i18nstrings' => 'finder:e15:settings][form][prefix',

),

'suffix' => array(

'#i18nstrings' => 'finder:e15:settings][form][suffix',

),

'default_value' => array(

'#i18nstrings' => 'finder:e15:settings][form][default_value',

),

),

'advanced' => array(

'delimit' => array(

'#i18nstrings' => 'finder:e15:settings][advanced][delimit',

),

),

),

),

),

'element_handler' => array(

'#title' => 'Select list',

'#module' => 'finder_optionwidgets',

),

'#_finder_object' => '1',

),

'3' => array(

'finder_element_id' => '17',

'finder_id' => '5',

'element' => 'text',

'title' => 'Full text search',

'weight' => '3',

'settings' => array(

'form' => array(

'description' => '',

'prefix' => '',

'prefix_format' => '2',

'suffix' => '',

'suffix_format' => '2',

'default_value' => '',

'required' => 0,

'field_prefix' => '',

'field_suffix' => '',

'maxlength' => '',

'minlength' => '',

'size' => '',

'rows' => '0',

),

'choices' => array(

'field' => array(

'node_data_field_services.field_services_value' => 'node_data_field_services.field_services_value',

'node_data_field_subtitle.field_subtitle_value' => 'node_data_field_subtitle.field_subtitle_value',

'node_data_field_text.field_text_value' => 'node_data_field_text.field_text_value',

'node_data_field_tips.field_tips_value' => 'node_data_field_tips.field_tips_value',

'node_data_field_additional_services.field_additional_services_value' => 'node_data_field_additional_services.field_additional_services_value',

'node.title' => 'node.title',

),

'displays' => array(

'query' => 'default',

),

'views' => array(

'args' => '',

'delimiter' => '/',

),

),

'advanced' => array(

'delimit' => '',

'value_combination' => '0',

),

'i18nstrings' => array(

'title' => array(

'#i18nstrings' => 'finder:e17:title',

),

'settings' => array(

'form' => array(

'description' => array(

'#i18nstrings' => 'finder:e17:settings][form][description',

),

'prefix' => array(

'#i18nstrings' => 'finder:e17:settings][form][prefix',

),

'suffix' => array(

'#i18nstrings' => 'finder:e17:settings][form][suffix',

),

'default_value' => array(

'#i18nstrings' => 'finder:e17:settings][form][default_value',

),

),

'advanced' => array(

'delimit' => array(

'#i18nstrings' => 'finder:e17:settings][advanced][delimit',

),

),

),

),

),

'element_handler' => array(

'#title' => 'Text',

'#module' => 'finder_text',

),

'#_finder_object' => '1',

),

),

'elements_index' => array(

'13' => 0,

'14' => 1,

'15' => 2,

'17' => 3,

),

'base_handler' => array(

'#title' => 'Views finder',

'#module' => 'finder_views',

),

'admin_links' => array(

'search' => 'View \"Path\"',

'admin/build/finder/5/edit' => 'Edit',

),

'links' => array(),

'#_finder_object' => '1',

)

网友答案:

My solution: since I don't need much of Finder features, I came up with an alternative solution using just Views:

  1. In the view listing all the nodes among which I'd like to search I added a filter Region:
    Filters > Taxonomy > Term (The taxonomy term ID) > "regions" vocabulary

  2. I exposed the filter, set it to dropdown and checked Show hierarchy in dropdown
    alt text http://i47.tinypic.com/zxmvea.jpg

  3. Then I exposed the form into a block
    alt text http://i45.tinypic.com/169p6wy.png

4 And enabled the block under admin/build/block

It works fine for me. :-)

网友答案:

For your requirement drupal's Hierarchical Select module will help you..

网友答案:

You can do this really easily without a Drupal module if you're just theming:

    $tree = taxonomy_get_tree($vid);

if ( $tree ) {

  $content .= '<select class="your-class">';
  $content .= '<option class="placeholder" value="">You Dropdown</option>';

  foreach ($tree as $term) {

       $path = taxonomy_term_path($term);
       $content .= '<option value="/terms/' . strtolower(str_replace( " ", "-",$term->name)) . '">' . $term->name . '</option>';           
  }

  $content .= '</select>';

}//end if ( $view )

return $content;

}

分享给朋友:
您可能感兴趣的文章:
随机阅读: