* Take a simple vocabulary with a few terms.
* Add a new term.
The value of 'hierarchy' in the table 'vocabulary' is incorrectly set to '1'. It should be set to '0' as per:
http://api.drupal.org/api/drupal/modules--taxonomy--taxonomy.module/func...
where it says:
"A hierarchy with no parents in any of its terms will be given a hierarchy of 0. If terms contain at most a single parent, the vocabulary will be given a hierarchy of 1. If any term contain multiple parents, the vocabulary will be given a hieararchy of 2."
* Now drag a term to the right which means it now has a parent and save.
* 'hierarchy' value will stay at '1'.
* Drag the term back to the left so that all terms are at the same base level and click save.
* 'hierarchy' value will now correctly change to '0'.
Furthermore,
* Delete a term.
(the function taxonomy_check_vocabulary_hierarchy() is called)
* 'hierarchy' value will now INCORRECTLY change to '1'.
So adding a term or deleting a term will wrongly set the 'hierarchy' value to '1'. But it looks like taxonomy_check_vocabulary_hierarchy() is only called when deleting a term.
My gut feeling is that the fault is in taxonomy_check_vocabulary_hierarchy() somewhere around the code
if ($term->tid == $changed_term['tid']) {
$term = (object) $changed_term;
$term->parents = $term->parent;
}My other feeling is that some devs somewhere have the wrong idea that a flat hierarchy should mean a value of '1'. This is wrong; 0 means flat, 1 means one or more terms have parents, 2 means some terms have more than one parent.
Comments
Comment #1
ch_masson commentedI have experienced the same issue.
$term is used for both an object of the returned taxonomy_get_tree array of term objects, and for the $changed_term object. I believe that's wrong.
I suggest to change to:
$changed_term_object = (object)$changed_term;
$term->parents = $changed_term_object->parents;
I also believe that there is another issue in taxonomy.admin.inc.
It says:
// Set the hierarchy to "multiple parents" by default. This simplifies the
// vocabulary form and standardizes the term form.
$form['hierarchy'] = array('#type' => 'value',
'#value' => '0',
);
I don't understand why "multiple parents" has a value of 0 when it should have a value of 2?
It also says
// Enable "related terms" by default.
$form['relations'] = array('#type' => 'value',
'#value' => '1',
);
I believe this is wrong because every time an admin will save a vocabulary, the 'hierarchy' value in the vocabulary table will be set to 0 and the 'relations' value in that same table will be set to 1.
I suggest to comment these lines out.
Comment #2
stpaultim commentedMarked this issue as a duplicate of the following: http://drupal.org/node/353775