Download & Extend

In combination with Hierarchical Select module, it doesn't work

Project:Taxonomy Defaults
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:postponed (maintainer needs more info)

Issue Summary

When you use the Hierarchical Select in order to select the forum section you want to appear, then the term is assigned to the new node, but the node doesn't appear in the forum section.

It works fine when you don't use the Hierarchical Select module.

Is there any way to make them compatible?

Thanks for this great module.

Comments

#1

Status:active» needs work

I can't reproduce the problem. Could you provide more detailed steps?

#2

Status:needs work» postponed (maintainer needs more info)

#3

It is easy, just install the hierarchical_select module and activate it to select the forum sections. At the same time, make sure that some autoassignements are configured. So, when you enter to the creation form, the hierarchical select combo for the forum section doesn't show the desired autoassigned value. Instead of that is shows nothing, so you have to select the forum by hand, and if you decide leaving empty, no forum section is assigned.

I hope my explanation could help.

Bye!

#4

I can confirm that taxonomy_defaults doesn't work when the hierarchical_select module is enabled for taxonomy select.

However, I think there is an easy solution by altering the module weight of taxonomy_default module from 1 to 3 (using the utility module).

This way, taxonomy defaults is called after HS. It worked in my case but probably needs some more testing.

#5

I can confirm this issue, Taxonomy default does'nt work in conjunction with Hyerarchical select, and confirm solution in #4 works for me too.

#6

Confirm this issue. - #4 does not work for me.
However, as I use "save lineage", HS may have trouble with a default term that is unique where it expects the full term hierarchy?

#7

Subscribe

#8

Subscribe
No it works, couldn't find the settings. Shame on me.

#9

I am having the same problem with these 2 modules not working together.

NOTE: I am using the latest versions of each; Taxonomy Defaults 6.x-2.1 and Hierarchical Select 6.x-3.7

When using them together I get the following error:
warning: Invalid argument supplied for foreach() in [MYSERVER]\sites\all\modules\hierarchical_select\includes\theme.inc on line 414.
which is referring to a $choices variable that doesn't get set - so that piece of code needs some work, but that is another story...

As the error only occurs with new nodes (node/add) and not with existing nodes (node/##/edit) I guessed it must be something with Taxonomy Defaults. I looked at the code in taxonomy_defaults_form_alter() function as that is where it is making the change to the node form, and all it does it set the #default_value to an array of tids which makes perfect sense. So what could be the problem...

I decided to looked at the value of '#default_value' and Hierarchical Select does it a little differently.

Both use arrays...
Taxonomy Defaults sends a keyed array ([tid] => tid, [tid]=> tid, [tid] => tid)
but...
Hierarchical Select does not, it uses a simple array format (0 => tid, 1 => tid, 2 => tid)

If I changed Taxonomy Defaults to send a simple array, it worked fine.

So adding an IF statement to the taxonomy_defaults_form_alter() function and changing the array sent with the array_values() function if the vocabulary is using Hierarchical Select seems to do the trick.

NOTE: this solution has only gone thru some simple testing.

BEFORE at around line 112

<?php
     
else {
        if (
$visible) {
         
// Do not preselect terms on nodes that already have been edited
         
if (!isset($node->nid)) {
             
$form['taxonomy'][$vid]['#default_value'] = $default_tids;
          }
        }
?>

AFTER

<?php
     
else {
        if (
$visible) {
         
// Do not preselect terms on nodes that already have been edited
         
if (!isset($node->nid)) {
            if (
$form['taxonomy'][$vid]['#type'] == 'hierarchical_select') {
             
// use simple array if using hierarchical_select module
             
$form['taxonomy'][$vid]['#default_value'] = array_values($default_tids);
            }
            else {
             
// use taxonomy array as created
             
$form['taxonomy'][$vid]['#default_value'] = $default_tids;
            }           
          }
}
?>