You are here

function taxonomy_manager_tree_build_form in Taxonomy Manager 5

Same name and namespace in other branches
  1. 6.2 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 1716
Taxonomy Manager

Code

function taxonomy_manager_tree_build_form(&$index, $tree, &$form, $root_form, $parents = array(), $build_subtrees = TRUE, $page = 0) {
  $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;
    $form[$term->tid]['checkbox'] = array(
      '#type' => 'checkbox',
      '#title' => $term->name,
      '#return_value' => 1,
      '#theme' => 'taxonomy_manager_tree_checkbox',
    );
    if ($root_form['#link']) {
      $form[$term->tid]['checkbox']['#link'] = $root_form['#link'] . '/' . $term->tid;
    }
    $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',
      ),
    );
    if (is_array($root_form['#operations'])) {
      $form[$term->tid]['operations'] = $root_form['#operations'];
    }
    if ($page) {
      if ($index == variable_get('taxonomy_manager_pager_tree_page_size', 50) - 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]);
    $index++;
    if ($build_subtrees) {
      if ($tree[$index]->depth > $current_depth) {
        $form[$term->tid]['#attributes']['class'] .= _taxonomy_manager_tree_term_get_class($index - 1, $tree);
        taxonomy_manager_tree_build_form($index, $tree, $form[$term->tid]['children'], $root_form, array_merge($this_parents, array(
          'children',
        )));
      }
      else {
        if (count($tree) - 1 == $index - 1 || $tree[$index]->depth < $current_depth) {
          $form[$term->tid]['#attributes']['class'] .= 'last ';
        }
      }
    }
    else {
      if (_taxonomy_manager_tree_term_has_children($term->tid)) {
        $form[$term->tid]['#attributes']['class'] .= 'has-children ';
        if ($index - 1 == count($tree) - 1) {
          $form[$term->tid]['#attributes']['class'] .= 'lastExpandable ';
        }
        else {
          $form[$term->tid]['#attributes']['class'] .= 'expandable ';
        }
      }
      else {
        if ($index - 1 == count($tree) - 1) {
          $form[$term->tid]['#attributes']['class'] .= 'last ';
        }
      }
    }
  }
}