| 5 taxonomy.module | _taxonomy_term_select($title, $name, $value, $vocabulary_id, $description, $multiple, $blank, $exclude = array()) |
| 6 taxonomy.module | _taxonomy_term_select($title, $name, $value, $vocabulary_id, $description, $multiple, $blank, $exclude = array()) |
Create a select form element for a given taxonomy vocabulary.
NOTE: This function expects input that has already been sanitized and is safe for display. Callers must properly sanitize the $title and $description arguments to prevent XSS vulnerabilities.
Parameters
$title: The title of the vocabulary. This MUST be sanitized by the caller.
$name: Ignored.
$value: The currently selected terms from this vocabulary, if any.
$vocabulary_id: The vocabulary ID to build the form element for.
$description: Help text for the form element. This MUST be sanitized by the caller.
$multiple: Boolean to control if the form should use a single or multiple select.
$blank: Optional form choice to use when no value has been selected.
$exclude: Optional array of term ids to exclude in the selector.
Return value
A FAPI form array to select terms from the given vocabulary.
See also
2 calls to _taxonomy_term_select()
File
- modules/
taxonomy/ taxonomy.module, line 1126 - Enables the organization of content into categories.
Code
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[''] = $blank;
}
if ($tree) {
foreach ($tree as $term) {
if (!in_array($term->tid, $exclude)) {
$choice = new stdClass();
$choice->option = array($term->tid => str_repeat('-', $term->depth) . $term->name);
$options[] = $choice;
}
}
}
return array(
'#type' => 'select',
'#title' => $title,
'#default_value' => $value,
'#options' => $options,
'#description' => $description,
'#multiple' => $multiple,
'#size' => $multiple ? min(9, count($options)) : 0,
'#weight' => -15,
'#theme' => 'taxonomy_term_select',
);
}
Login or register to post comments
Comments
Wondering why the '#weight'
Wondering why the '#weight' is set to -15.
So it floats
So it floats to the top of the node display.
Reverse order
How to override this function to display select options ordered alphabetically descending?
Nevermind. I did it in
Nevermind. I did it in theme_taxonomy_term_select().
In case someone need solution here it is:
<?php
function phptemplate_taxonomy_term_select($element) {
$element['#options']=array_reverse($element['#options']);
unset($element['#options']['']);
print_r($element['#options']);
$select = '';
$size = $element['#size'] ? ' size="' . $element['#size'] . '"' : '';
_form_set_class($element, array('form-select'));
$multiple = $element['#multiple'];
return theme('form_element', $element, '<select name="' . $element['#name'] . '' . ($multiple ? '[]' : '') . '"' . ($multiple ? ' multiple="multiple" ' : '') . drupal_attributes($element['#attributes']) . ' id="' . $element['#id'] . '" ' . $size . '>' . form_select_options($element) . '</select>');
}
?>