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 17:01:40 -0000 @@ -217,15 +217,15 @@ $exclude[] = $edit['tid']; if ($vocabulary->hierarchy == 1) { - $form .= _taxonomy_term_select(t('Parent'), 'parent', $parent, $vocabulary_id, l(t('Parent term'), 'admin/help/taxonomy', NULL, NULL, 'parent') .'.', 0, '<'. t('root') .'>', $exclude); + $form .= theme('taxonomy_term_select', t('Parent'), 'parent', $parent, $vocabulary_id, l(t('Parent term'), 'admin/help/taxonomy', NULL, NULL, 'parent') .'.', 0, '<'. t('root') .'>', $exclude); } elseif ($vocabulary->hierarchy == 2) { - $form .= _taxonomy_term_select(t('Parents'), 'parent', $parent, $vocabulary_id, l(t('Parent terms'), 'admin/help/taxonomy', NULL, NULL, 'parent') .'.', 1, '<'. t('root') .'>', $exclude); + $form .= theme('taxonomy_term_select', t('Parents'), 'parent', $parent, $vocabulary_id, l(t('Parent terms'), 'admin/help/taxonomy', NULL, NULL, 'parent') .'.', 1, '<'. t('root') .'>', $exclude); } } if ($vocabulary->relations) { - $form .= _taxonomy_term_select(t('Related terms'), 'relations', array_keys(taxonomy_get_related($edit['tid'])), $vocabulary_id, NULL, 1, '<'. t('none') .'>', array($edit['tid'])); + $form .= theme('taxonomy_term_select', t('Related terms'), 'relations', array_keys(taxonomy_get_related($edit['tid'])), $vocabulary_id, NULL, 1, '<'. t('none') .'>', array($edit['tid'])); } $form .= form_textarea(t('Synonyms'), 'synonyms', implode("\n", taxonomy_get_synonyms($edit['tid'])), 60, 5, t('Synonyms of this term, one synonym per line.', array('%help-url' => url('admin/help/taxonomy', NULL, NULL, 'synonyms')))); @@ -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 theme('taxonomy_term_select', check_plain($title), $name, $value, $vid, $help, intval($vocabulary->multiple), $blank); } /** @@ -870,26 +885,11 @@ return db_fetch_object(db_query('SELECT * FROM {term_data} WHERE tid = %d', $tid)); } +/** + * deprecated. Please use theme('taxonomy_term_select'...) + */ 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 +1288,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