function _i18ntaxonomy_term_select in Internationalization 5.2
Same name and namespace in other branches
- 5.3 contrib/i18ntaxonomy.module \_i18ntaxonomy_term_select()
- 5 contrib/i18ntaxonomy.module \_i18ntaxonomy_term_select()
- 6 i18ntaxonomy/i18ntaxonomy.module \_i18ntaxonomy_term_select()
1 call to _i18ntaxonomy_term_select()
- i18ntaxonomy_form in contrib/
i18ntaxonomy.module - Generate a form element for selecting terms from a vocabulary. Translates all translatable strings.
File
- contrib/
i18ntaxonomy.module, line 193 - Internationalization (i18n) package - taxonomy term translation
Code
function _i18ntaxonomy_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)) {
$choice = new stdClass();
$choice->option = array(
$term->tid => str_repeat('-', $term->depth) . t($term->name),
);
$options[] = $choice;
}
}
if (!$blank && !$value) {
// required but without a predefined value, so set first as predefined
$value = $tree[0]->tid;
}
}
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',
);
}