You are here

function _tss_next_nested in Taxonomy Super Select (TSS) 6

Same name and namespace in other branches
  1. 5 taxonomy_super_select.module \_tss_next_nested()

Recursive function to allow infinite depth vocabularies.

Parameters

array &$terms The result of taxonomy_get_tree for the vocabulary's $vid.:

array &$vid The vocabulary to work on. Passed by reference just to keep overhead: of copies down.

array &$input The portion of the vocabulary to look at (parent_type?). Passed by: reference just to keep overhead of copies down.

array $tss These are the settings for this module.:

array &$form_node This is a subsection of $form, namely $form['#node'] should be: passed in.

array &$form_branch This is a subsection of $form. Each iteration adds to the one: before, then passes itself as the new branch. _tss_branch() is called for each iteration and appended to it.

Return value

since values are passed in via reference, no return value is required.

1 call to _tss_next_nested()
taxonomy_super_select_form_alter in ./taxonomy_super_select.module
@file Changes the default taxonomy select box into checkbox or radio buttons.

File

./taxonomy_super_select.module, line 289
Changes the default taxonomy select box into checkbox or radio buttons.

Code

function _tss_next_nested(&$terms, &$vid, &$input, $tss, &$form_node, &$form_branch) {
  $fieldweight = 0;
  foreach ($terms as $index => $term) {
    $children = taxonomy_get_children($term->tid, $vid);
    if (count($children)) {
      if (!empty($tss[$vid]['parents'])) {
        $term->is_parent = TRUE;
        $term->parent_type = $input;
        $term->parent_value = isset($form_node->taxonomy[$term->tid]->tid) ? $form_node->taxonomy[$term->tid]->tid : NULL;
      }
      $form_branch[$term->tid] = _tss_branch($vid, $term, NULL, 'fieldset', ++$fieldweight);
      _tss_next_nested($children, $vid, $input, $tss, $form_node, $form_branch[$term->tid]);

      // if any of the children is selected, then the parent is not collapsed
      foreach ($children as $child) {

        // check, is one of the direct children terms selected
        if (!empty($form_node->taxonomy[$child->tid]->tid)) {
          $form_branch[$term->tid]['#collapsed'] = FALSE;
          break;
        }

        // check, if child is a fieldset and if it is not collapsed
        if (array_key_exists($child->tid, $form_branch[$term->tid]) && $form_branch[$term->tid][$child->tid]['#type'] == 'fieldset' && !$form_branch[$term->tid][$child->tid]['#collapsed']) {
          $form_branch[$term->tid]['#collapsed'] = FALSE;
          break;
        }
      }
    }
    else {

      //I don't know why the code is put *before*, it's useless

      //if ($value =  $form_node->taxonomy[$term->tid]->tid) {

      //  $form_branch[$term->tid]['#collapsed'] = FALSE;

      //}
      $form_branch[$term->tid] = _tss_branch($vid, $term, @$form_node->taxonomy[$term->tid]->tid, $input, ++$fieldweight);

      // Taxonomy Image support
      if ($tss[$vid]['image']) {
        $image = taxonomy_image_display($term->tid);
        $form_branch[$term->tid]['#title'] = $image . ' ' . $form_branch[$term->tid]['#title'];
      }
    }
  }
}