Index: modules/taxonomy.module =================================================================== RCS file: /cvs/drupal/drupal/modules/taxonomy.module,v retrieving revision 1.222 diff -u -r1.222 taxonomy.module --- modules/taxonomy.module 28 Aug 2005 16:30:50 -0000 1.222 +++ modules/taxonomy.module 12 Sep 2005 13:58:09 -0000 @@ -418,8 +418,21 @@ /** * Generate a form element for selecting terms from a vocabulary. + * + * @param $vid + * Vocabulary id. + * @param $value + * The currently selected value. + * @param $help + * The description of what this vocabulary represents. If NULL, the value is + * taken from the vocabulary itself ($vocabulary->help). + * @param $name + * The name parameter of the form item being built. Set this if you want to use + * the vocabulary list to set fields other than taxonomy. + * @param $title + * The label on the form item. If left NULL, it will default to the vocabulary name. */ -function taxonomy_form($vid, $value = 0, $help = NULL, $name = 'taxonomy') { +function taxonomy_form($vid, $value = 0, $help = NULL, $name = 'taxonomy', $title = NULL) { $vocabulary = taxonomy_get_vocabulary($vid); $help = ($help) ? $help : $vocabulary->help; if ($vocabulary->required) { @@ -428,8 +441,10 @@ else { $blank = '<'. t('none') .'>'; } - - return _taxonomy_term_select(check_plain($vocabulary->name), $name, $value, $vid, $help, intval($vocabulary->multiple), $blank); + if (is_null($title)) { + $title = $vocabulary->name; + } + return _taxonomy_term_select(check_plain($title), $name, $value, $vid, $help, intval($vocabulary->multiple), $blank); } /** @@ -871,25 +886,7 @@ } function _taxonomy_term_select($title, $name, $value, $vocabulary_id, $description, $multiple, $blank, $exclude = array()) { - $tree = taxonomy_get_tree($vocabulary_id); - $options = array(); - - if ($blank) { - $options[0] = $blank; - } - if ($tree) { - foreach ($tree as $term) { - if (!in_array($term->tid, $exclude)) { - $options[$term->tid] = _taxonomy_depth($term->depth, '-') . $term->name; - } - } - if (!$blank && !$value) { - // required but without a predefined value, so set first as predefined - $value = $tree[0]->tid; - } - } - - return form_select($title, $name . ($multiple ? '' : ']['), $value, $options, $description, $multiple ? 'size="'. min(12, count($options)) .'"' : 0, $multiple); + return theme('taxonomy_term_select', $title, $name, $value, $vocabulary_id, $description, $multiple, $blank, $exclude); } function _taxonomy_depth($depth, $graphic = '--') { @@ -1288,4 +1285,47 @@ } } +/** + * Theme a form element for selecting terms from a vocabulary. + * + * @param $title + * The label on the form item. If left NULL, it will default to the vocabulary name. + * @param $name + * The name parameter of the form item being built. Set this if you want to use + * the vocabulary list to set fields other than taxonomy. + * @param $value + * The currently selected value. + * @param $vid + * Vocabulary id. + * @param $description + * The description of what this vocabulary represents. If NULL, the value is + * taken from the vocabulary itself ($vocabulary->help). + * @param $multiple + * Can multiple terms be selected? + * @param $blank + * If this form element is not required, the $blank element will be the first + * in the list. + * @param $exclude + * an array of term ids that shouldn't appear in the list. + */ +function theme_taxonomy_term_select($title, $name, $value, $vocabulary_id, $description, $multiple, $blank, $exclude = array()) { + $tree = taxonomy_get_tree($vocabulary_id); + $options = array(); + if ($blank) { + $options[0] = $blank; + } + if ($tree) { + foreach ($tree as $term) { + if (!in_array($term->tid, $exclude)) { + $options[$term->tid] = _taxonomy_depth($term->depth, '-') . $term->name; + } + } + if (!$blank && !$value) { + // required but without a predefined value, so set first as predefined + $value = $tree[0]->tid; + } + } + + return form_select($title, $name . ($multiple ? '' : ']['), $value, $options, $description, $multiple ? 'size="'. min(12, count($options)) .'"' : 0, $multiple); +} \ No newline at end of file