diff options
-rw-r--r-- | taxonomy_node_tree.module | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/taxonomy_node_tree.module b/taxonomy_node_tree.module index 2d1fbc7..18184c6 100644 --- a/taxonomy_node_tree.module +++ b/taxonomy_node_tree.module @@ -219,18 +219,19 @@ function taxonomy_node_tree_get_empty($term, $clean = FALSE, &$list = array()) { * @param $clean * Set to true to cleanup term before adding to list. * + * @param $parents + * Set to TRUE to keep parent nodes even if they don't have + * descendant nodes. + * * @param $list * Array to store term list. * * @return * Array with terms with descendant nodes. - * - * @todo - * Skip parents should be controlled by a parameter. */ -function taxonomy_node_tree_get_non_empty($term, $clean = FALSE, &$list = array()) { +function taxonomy_node_tree_get_non_empty($term, $clean = FALSE, $parents = FALSE, &$list = array()) { // Add parents and terms with descendant nodes. - if ($term->parents[0] == 0 || taxonomy_node_tree_count($term) > 0) { + if (($term->parents[0] == 0 && $parents) || taxonomy_node_tree_count($term) > 0) { $save = drupal_clone($term); if ($clean == TRUE) { @@ -244,7 +245,7 @@ function taxonomy_node_tree_get_non_empty($term, $clean = FALSE, &$list = array( if (is_array($term->below)) { foreach ($term->below as $below) { - taxonomy_node_tree_get_non_empty($below, $clean, $list); + taxonomy_node_tree_get_non_empty($below, $clean, $parents, $list); } } @@ -266,10 +267,14 @@ function taxonomy_node_tree_get_non_empty($term, $clean = FALSE, &$list = array( * @param $clean * Set to TRUE to remove branches without descendant nodes. * + * @param $parents + * Set to TRUE to keep parent nodes even if they don't have + * descendant nodes. Used just when $clean is also set to TRUE. + * * @return * Hierarchical tree. */ -function taxonomy_node_tree_build($nodes, $terms, $clean = FALSE) { +function taxonomy_node_tree_build($nodes, $terms, $clean = FALSE, $parents = FALSE) { $tree = taxonomy_node_tree_index($nodes, $terms); $tree = taxonomy_node_tree_relation($tree); $tree = taxonomy_node_tree_hierarchy($tree); @@ -277,7 +282,7 @@ function taxonomy_node_tree_build($nodes, $terms, $clean = FALSE) { if ($clean == TRUE && is_array($tree)) { $terms = array(); foreach ($tree as $term) { - $list = taxonomy_node_tree_get_non_empty($term, TRUE); + $list = taxonomy_node_tree_get_non_empty($term, TRUE, $parents); $terms = array_merge($terms, $list); } |