Drupal:如何使选择列表在层次结构中显示分类术语?

时间:2010-05-18 08:14:25

标签: drupal drupal-6 drupal-modules drupal-taxonomy

我有Finder module生成的块(简单搜索机制)。该块包含一个表单,其中包含各种分类词典的选择列表。 然而,它们的顺序似乎是随机的(既不是按字母顺序排列的,也不是按时间顺序排列的),并按照没有层次结构的顺序列出区域:
Italy, France, Poland, Benelux, ..., Upper Austria, ... Switzerland, Tyrol, Croatia
alt text http://i42.tinypic.com/24owysj.jpg

我期望的顺序是我的字典层次结构,所以:
Austria, Austria>Tyrol, Austria>Upper Austria, Benelux, Croatia, France, Italy, Poland, Switzerland

您是否知道如何使选择列表项以字典层次结构顺序显示?


修改:Finder配置:

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',
)

3 个答案:

答案 0 :(得分:1)

我的解决方案:由于我不需要很多Finder功能,因此我想出了一个仅使用视图的替代解决方案:

  1. 在列出我想要搜索的所有节点的视图中,我添加了一个过滤器Region
    Filters > Taxonomy > Term (The taxonomy term ID) > "regions" vocabulary

  2. 公开过滤器,将其设置为下拉列表并检查Show hierarchy in dropdown
    alt text http://i47.tinypic.com/zxmvea.jpg

  3. 然后我将表单暴露成块
    alt text http://i45.tinypic.com/169p6wy.png

  4. 4并在admin/build/block

    下启用了该块

    对我来说很好。 : - )

答案 1 :(得分:1)

根据您的要求,drupal的Hierarchical Select模块将帮助您..

答案 2 :(得分:1)

如果你只是主题,你可以在没有Drupal模块的情况下轻松完成这项工作:

    $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;

}