Taxonomy search with hierarchical select
I needed a jump-to drop-down facility for my taxonomy so I wrote this with the help of Wim (the author of hierarchical_select). You will need to install that module and its prerequisites to get this to work.
<?php
function handset_search_block($op = 'list', $delta = 0, $edit = array()){
switch ($op) {
case 'list' :
$blocks[0]['info'] = t("Handset Search");
return $blocks;
break;
case 'view' :
$output = drupal_get_form('handset_search_dropdown_form');
$block['subject'] = t('Search');
$block['content'] = $output;
return $block;
break;
case 'configure' :
$cForm['handset_select_vid'] = array(
'#type' => 'textfield',
'#default_value' => variable_get('handset_select_vid', "0"),
'#title' => t('Vocabulary ID'),
'#size' => 6,
'#maxlength' => 5,
'#description' => t("Choose the vid of the taxonomy you wish to display")
);
return $cForm;
break;
case 'save' :
variable_set('handset_select_vid', $edit['handset_select_vid']);
break;
}
}
function handset_search_dropdown_form() {
$vid = variable_get('handset_select_vid', "0");
$vtree = taxonomy_get_tree($vid);
if($vtree) {
foreach ($vtree as $key => $term) {
$choice = new stdClass();
$choice->option = array($term->tid => str_repeat('-', $term->depth) . $term->name);
$options[] = $choice;
}
}
$vocabulary = taxonomy_get_vocabulary($vid);
if ($vocabulary->hierarchy > 0) {
$form['tid'] = array(
'#type' => 'hierarchical_select',
'#title' => t('Search handsets'),
'#options' => $options,
'#tree' => true,
'#default_value' => '0',
'#hierarchical_select_settings' => array(
'module' => 'taxonomy',
'params' => array(
'vid' => $vid,
),
),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('go'),
);
}
return $form;
}
function handset_search_dropdown_form_submit($form_id, $form_values) {
drupal_goto("taxonomy/term/".$form_values['tid']);
}
?>This module isn't quite generic enough for a full module release but maybe in time it will be.
