You are here

function taxonomy_manager_tree_build_form in Taxonomy Manager 6.2

Same name and namespace in other branches
  1. 5 taxonomy_manager.module \taxonomy_manager_tree_build_form()
  2. 6 taxonomy_manager.module \taxonomy_manager_tree_build_form()
  3. 7 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 599
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()) {
  $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,
      '#value' => $value,
      '#return_value' => $term->tid,
      '#theme' => $multiple ? 'taxonomy_manager_tree_checkbox' : 'taxonomy_manager_tree_radio',
    );
    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' => 'weight-form',
        ),
      );
      $form[$term->tid]['tid'] = array(
        '#type' => 'hidden',
        '#value' => $term->tid,
        '#attributes' => array(
          'class' => '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', 50) - 1 && !isset($tree[$index + 1])) {
        $module_path = drupal_get_path('module', 'taxonomy_manager') . '/';
        $form[$term->tid]['has-more-siblings'] = array(
          '#type' => 'markup',
          '#value' => theme("image", $module_path . "images/2downarrow.png", "more", NULL, array(
            'class' => 'load-siblings',
          )),
        );
        $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(
          '#value' => $next_count,
        );
        $form[$term->tid]['#attributes']['class'] .= 'has-more-siblings ';
      }
    }
    _taxonomy_manager_tree_element_set_params($this_parents, $form[$term->tid]);
    $class = _taxonomy_manager_tree_term_get_class($index, $tree, $root_form['#expand_all'] || in_array($term->tid, $terms_to_expand));
    if (!empty($class)) {
      $form[$term->tid]['#attributes']['class'] .= $class;
    }
    $index++;
    if ($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);
    }
  }
}