Closed (fixed)
Project:
Taxonomy Manager
Version:
6.x-1.0-beta1
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
19 Aug 2008 at 15:06 UTC
Updated:
3 Sep 2008 at 15:52 UTC
Suppose that:
Then Taxonomy Manager expands all the possible parents of the default value. But because this is a single selection tree it uses radio buttons, so only one of the possible terms is selected. This results in a tree which has expanded branches by default even though no items are selected under those branches.
Only one of the possible parents should be expanded.
I did this using the Content Taxonomy module (though I believe the problem is within the realm of Taxonomy Manager - see the patch).
This patch ensures that when using radio buttons only one parent is expanded ; and it ensures that the right item (the one with the expanded parents) gets marked as checked.
Index: taxonomy_manager/taxonomy_manager.module
===================================================================
--- taxonomy_manager/taxonomy_manager.module (revision 1269)
+++ taxonomy_manager/taxonomy_manager.module (working copy)
@@ -333,7 +333,7 @@
$terms_to_expand = array();
if (count($element['#default_value']) && !$element['#expand_all']) {
- $terms_to_expand = taxonomy_manager_tree_get_terms_to_expand($tree, $element['#default_value']);
+ $terms_to_expand = taxonomy_manager_tree_get_terms_to_expand($tree, $element['#default_value'], $element['#multiple']);
}
taxonomy_manager_tree_build_form($index = 0, $tree, $element['#elements'], $element, $element['#parents'], !$element['#pager'], $element['#siblings_page'], $element['#default_value'], $element['#multiple'], $terms_to_expand);
@@ -380,7 +380,7 @@
/**
* marks parent terms to expand if a child terms is selected by default
*/
-function taxonomy_manager_tree_get_terms_to_expand($tree, $default_values) {
+function taxonomy_manager_tree_get_terms_to_expand($tree, $default_values, $multiple) {
$terms = array();
foreach (array_reverse($tree) as $term) {
if (in_array($term->tid, array_values($default_values)) || in_array($term->tid, $terms)) {
@@ -389,6 +389,9 @@
if ($parent) {
$terms[$parent] = $parent;
}
+ if (!$multiple) {
+ break;
+ }
}
}
}
@@ -418,10 +421,21 @@
$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' => in_array($term->tid, $default_value) ? 1 : 0,
+ '#value' => $value,
'#return_value' => $term->tid,
'#theme' => ($multiple) ? 'taxonomy_manager_tree_checkbox' : 'taxonomy_manager_tree_radio',
);
Comments
Comment #1
mh86 commentedhi!
I agree, that it's better to expand only the first parent instead of every one. Thanks for providing a patch - I know this part of the taxonomy manager is a bit more complicated ;)
I committed the patch to the dev version and will be included in the next release.
Comment #2
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.