function taxonomy_manager_tree_build_form in Taxonomy Manager 7
Same name and namespace in other branches
- 5 taxonomy_manager.module \taxonomy_manager_tree_build_form()
- 6.2 taxonomy_manager.module \taxonomy_manager_tree_build_form()
- 6 taxonomy_manager.module \taxonomy_manager_tree_build_form()
recursive function for building nested form array with checkboxes and weight forms for each term
nested form array are allways appended to parent-form['children']
Parameters
$index current index in tree, start with 0:
$tree of terms (generated by taxonomy_get_tree):
Return value
a form array
1 call to taxonomy_manager_tree_build_form()
- taxonomy_manager_tree_process_elements in ./
taxonomy_manager.module - Processes the tree form element
File
- ./
taxonomy_manager.module, line 575 - Taxonomy Manager
Code
function taxonomy_manager_tree_build_form(&$index, $tree, &$form, $root_form, $parents = array(), $page = 0, $default_value = array(), $multiple = TRUE, $terms_to_expand = array(), $terms_to_highlight = array()) {
$current_depth = $tree[$index]->depth;
while ($index < count($tree) && $tree[$index]->depth >= $current_depth) {
$term = $tree[$index];
$attributes = array();
$this_parents = $parents;
$this_parents[] = $term->tid;
$value = in_array($term->tid, $default_value) ? 1 : 0;
if ($value && !$multiple) {
// Find our direct parent
$newindex = $index;
while ($newindex >= 0 && $tree[$newindex]->depth >= $current_depth) {
$newindex--;
}
if ($newindex >= 0) {
$value = in_array($tree[$newindex]->tid, $terms_to_expand) ? 1 : 0;
}
}
$form[$term->tid]['checkbox'] = array(
'#type' => $multiple ? 'checkbox' : 'radio',
'#title' => $term->name,
// Escaping is done in theme wrappers.
'#value' => $value,
'#return_value' => $term->tid,
'#required' => FALSE,
'#theme_wrappers' => $multiple ? array(
'taxonomy_manager_tree_checkbox',
) : array(
'taxonomy_manager_tree_radio',
),
'#highlight' => in_array($term->tid, $terms_to_highlight) ? TRUE : FALSE,
);
$form[$term->tid]['#attributes'] = array();
if (!empty($root_form['#link_callback'])) {
$link_callback = $root_form['#link_callback'];
if (function_exists($link_callback)) {
$form[$term->tid]['checkbox']['#link'] = $link_callback($term);
}
}
if ($root_form['#add_term_info']) {
$form[$term->tid]['weight'] = array(
'#type' => 'hidden',
'#value' => $term->weight,
'#attributes' => array(
'class' => array(
'weight-form',
),
),
);
$form[$term->tid]['tid'] = array(
'#type' => 'hidden',
'#value' => $term->tid,
'#attributes' => array(
'class' => array(
'term-id',
),
),
);
$form[$term->tid]['checkbox']['#extra_info'] = taxonomy_manager_tree_term_extra_info($term);
}
if (!empty($root_form['#operations_callback'])) {
$opertions_callback = $root_form['#operations_callback'];
if (function_exists($opertions_callback)) {
$form[$term->tid]['operations'] = $opertions_callback($term);
}
}
if ($page) {
if ($index == variable_get('taxonomy_manager_pager_tree_page_size', TAXONOMY_MANAGER_PAGER_TREE_PAGE_SIZE_DEFAULT) - 1 && !isset($tree[$index + 1])) {
$form[$term->tid]['page'] = array(
'#type' => 'hidden',
'#value' => $page,
'#attributes' => array(
'class' => 'page',
),
);
$next_count = _taxonomy_manager_tree_get_next_siblings_count($term->vid, $page, $root_form['#parent']);
$form[$term->tid]['next_count'] = array(
'#markup' => $next_count,
);
$form[$term->tid]['#attributes']['class'][] = 'has-more-siblings';
}
}
_taxonomy_manager_tree_element_set_params($this_parents, $form[$term->tid]);
_taxonomy_manager_tree_term_set_class($form[$term->tid]['#attributes']['class'], $index, $tree, $root_form['#expand_all'] || in_array($term->tid, $terms_to_expand));
$index++;
if (isset($tree[$index]) && $tree[$index]->depth > $current_depth) {
taxonomy_manager_tree_build_form($index, $tree, $form[$term->tid]['children'], $root_form, array_merge($this_parents, array(
'children',
)), $page, $default_value, $multiple, $terms_to_expand, $terms_to_highlight);
}
}
}