In strictly hierarchical systems (vocabularies) only the lowest level of hierarchy are meant to have own items.

Could we have this option in this module, that while editing a node with ct field, the whole or part of a tree of a vocabulary will be displayed, but only lowest terms can be checked or select.
a) If "Depth of taxonomy tree:" =empty the lowest level
b) if "Depth of taxonomy tree:" = p.e. 1 only first level

for example:

vocabulary
- parent1
-- term 1-1
-- subterm 1-1
-- term 1-2
-- subterm 1-2
-- term 1-3
-- subterm 1-3
- parent2
-- term 2-1

In case a) all subterms and term 2-1 could be be checked or select.
in case b)
"Depth of taxonomy tree:" = 1 all terms 1- and terms 2- could be chosen
"Depth of taxonomy tree:" = 0 only parent items are aktive.

With the current options users could check or chose any of the displayed terms (or not? Am I overlooking a way to change that?)

Together with the taxonomy menu module (version3 in preparation) this could be a great feature to have clear menu and content structure.
See: http://drupal.org/project/taxonomy_menu

Thanks - content taxonomy is a great module!!
Klaus

Comments

ksc’s picture

Nobody else is supportung this idea?
It is about letting users only check lowest level in hierarchical taxonomy.

ksc’s picture

Assigned: ksc » Unassigned
janusman’s picture

I am trying to get this done in the 5.x version. I could report back with a patch for that that'd hopefully work in the 6.x version.

janusman’s picture

For a clue, see http://drupal.org/node/76500

The key (I think!) is using the optgroup facility in #options arrays in Form API. Instead of having an option tree:

"#options" = array(
  1 => "parent term tid 1 which you want unselectable", 
  2 => "term tid 2", 
  3 => "term tid 3"
)

you need to make an array of arrays of options:

"#options" = array(
  "parent term (now unselectable)" => array(
    2 => "term tid 2", 
    3 => "term tid 3"
  )
)

You could do this using hook_form_alter() from another module, or we could work it into this module (I will try the first thing first).

janusman’s picture

Status: Active » Needs review

Sadly, Form API does not allow nested optgroups, that is, we can only make optgroups for the first-level terms. I have this working under version 5.x-1.x-dev, ugly ugly code follows.

To get it to work you have to specify a negative depth (instead of "2" you say -2 to have this patch kick in).

--- content_taxonomy/content_taxonomy_options.module    2009-03-25 18:17:25.369406874 -0600
+++ ../../prod68ws.ruv.itesm.mx/modules/content_taxonomy/content_taxonomy_options.module        2009-03-25 19:14:24.143256262 -0600
@@ -180,6 +180,12 @@
 function content_taxonomy_options_array($vid, $parent = NULL, $depth = 0, $blank_field = TRUE, $show_depth = FALSE) {
   $options = array();

+  // Handle first level optgroups when $depth is negative
+  $first_level_optroup = FALSE;
+  if ($depth < 0) {
+    $first_level_optroup_flag = TRUE;
+    $depth = -$depth;
+  }
   if ($depth == 1) {
     $tree = taxonomy_get_children($parent, $vid);
   }
@@ -200,7 +206,29 @@
       else {
         $value = $term->name;
       }
-      $options[$term->tid] = $value;
+
+      if ($first_level_optroup_flag) {
+        $parents = taxonomy_get_parents($term->tid);
+        sort($parents);
+        $parent_tid = $parents[0]->tid;
+        if (sizeof($parents) == 0) {
+          // Does it have children?
+          if (sizeof($children = taxonomy_get_children($term->tid)) == 0) {
+            $options[$term->tid] = $value;
+          } else {
+            $first_level_groupname[$term->tid] = $term->name;
+          }
+        } else {
+          if ($first_level_groupname[$parent_tid]) {
+            $options[$first_level_groupname[$parent_tid]][] = $value;
+          } else {
+            $options[$term->tid] = $value;
+          }
+        }
+      } else {
+        $options[$term->tid] = $value;
+      }
+
     }
   }
   return $options;
upupax’s picture

subscribing.
but I can't apply the above patch to last -dev package, I get error: malformed patch at line 4.

ksc’s picture

Hi janusman, thanks for your mailing the code.
I´m not into PHP and I use Drupal 6.

ksc’s picture

As an option for "only lowest level terms are selectable" I suggest the function:
"Parental terms automatically get selected".
This would make it easier to use hierarchical path structures within the Taxonomy Menu module.

Please see: http://drupal.org/node/428004

ksc’s picture

I found out that http://drupal.org/project/hierarchical_select can do that.
Unfortunately it can´t beeing used yet within content taxonomy.

janusman’s picture

@ksc: Hierarchical Select support is moving closer =)

Check out: #342992: Port HS support for Content Taxonomy to Drupal 6

janusman’s picture

Status: Needs review » Closed (fixed)

Closing due to HS support now solved.

grzegorz.bartman’s picture

StatusFileSize
new1.31 KB

This is simple module, that disable checkbox on parents in Content Taxonomy Tree module
This is dev version.

lhugg’s picture

Title: Hirarchical vocabularies: only lowest level selectable » content_taxonomy_tree_addons-0.1 doesn't seem to do anything
Component: User interface » Option Widgets

I don't see that this did anything after it was installed. No extra checkboxes. I'm using Drupal 6.16. Is there any documentation for this module?

lhugg’s picture

Status: Closed (fixed) » Active
halmsx’s picture

thanks for the module!