The vocabulary edit form hardcodes the value of the 'hierarchy' flag to '0', therefore resetting it when the form is submitted and the vocabulary saved.

This flag is normally assigned though taxonomy_check_vocabulary_hierarchy() which is called when terms are modified.
I think it should be '0' when first creating a vocabulary, but preserved whenever an existing vocabulary is edited—which is what this tiny patch does.

Comments

David Lesieur’s picture

I'm surprised that no one seems to have stumbled onto this bug.

The patch still applies...

Mark Theunissen’s picture

Yep, I had noticed this before but thought nothing of it, until I installed Faceted Search and ran into the bug. Patch applies and solves the issue. Thanks David!

domidc’s picture

I confirm that the patch works. Also ran into it using faceted search.

David Lesieur’s picture

To others who might wonder: This is really a (trivial) bug in Drupal core. Faceted Search only springs up because only a few modules rely on this flag.

David Lesieur’s picture

Version: 6.x-dev » 7.x-dev
StatusFileSize
new932 bytes

Re-rolled patch for D7.

cburschka’s picture

Title: Vocabulary edit form resets the 'hierarchy' field to '0' » Vocabulary edit form resets the 'hierarchy' field to '0' and 'relations' field to '1'
Status: Needs review » Needs work

Neat, but could we fix the similarly hard-coded value of $form['relations'] just below it as well?

There's another slight WTF there: The defaults added to the $edit array at the top of the function make $edit['relations'] default to 0 - but the hard-coded form value forces it to 1. If we continue to enable relations by default, then this value should be changed in the defaults array.

David Lesieur’s picture

Status: Needs work » Needs review
StatusFileSize
new1.3 KB

Implemented the suggested fixes.

cburschka’s picture

Status: Needs review » Reviewed & tested by the community

Looks good now.

dries’s picture

Status: Reviewed & tested by the community » Needs work

Can we write a test for this please, or adjust the existing tests? Thanks!

stevenghines’s picture

Are there any plans to release this patch in the next 6.x version of Drupal? I too am using the faceted search module and found this issue via #420354: Subcategories / Terms not heirachical in Guided Search

netdreamer’s picture

yes, please... include it also in D6...
It's really a big issue to have to go back to database each time someone updates the hierarchy parameters...

bunker’s picture

Status: Needs work » Needs review

taxonomy-hierarchy.patch queued for re-testing.

nardberjean’s picture

taxonomy-hierarchy.patch queued for re-testing.

nardberjean’s picture

Appears to me like the d6 version is tested against d7 and fails, does it make any sense ?

dawehner’s picture

Status: Needs review » Needs work

The patch does not apply anymore

nardberjean’s picture

This patch is still recommanded on http://drupal.org/project/faceted_search , I assume for d6. If it is no more the case the project page should be modified, in my opinion.

tvb’s picture

Status: Needs work » Needs review

taxonomy-hierarchy.patch queued for re-testing.

DanielJohnston’s picture

Subscribing.

klonos’s picture

subscribing...

Eronarn’s picture

Nope. It doesn't make any sense to try and apply the d6 patch to d7.

If you are like me and stumble across this patch from the Faceted Search project page - it does work in d6! It will prevent the hierarchy bugginess from recurring whenever you edit a vocabulary, whereas just modifying the database values for 'hierarchy' would be a one-time fix.

nardberjean’s picture

The confusion came because #0 does not tell it is the version for D6, but #5 and #7 explicitely tell they are for D7. #5 also tells ''Version: 6.x-dev » 7.x-dev'' from that it can be deduced that #0 is for D6. It was just not obvious to me at first glance.

Eronarn’s picture

Version: 7.x-dev » 6.x-dev
Status: Needs review » Reviewed & tested by the community

I just updated core and ran into this issue again until I modified my database and reapplied the patch.

I'm changing the version on this to 6.x because, while D7 patches have been submitted, #0 is for D6 and the mismatched version is making it fail testing.

I'm changing the status on this to RTBC because this patch has been in use for over a year. Additionally it is very minor, has (in the D7 versions posted, which appear easily backported) met community suggestions for improvements, and fixes a problem that otherwise requires database edits.

I hope to see this in core some time before next year!

Eronarn’s picture

taxonomy-hierarchy.patch queued for re-testing.

David Lesieur’s picture

Status: Reviewed & tested by the community » Needs work

The next step for getting this patch committed is clear: We have to write a test case (see #9).

David Lesieur’s picture

Version: 6.x-dev » 7.x-dev

The usual process at this point would also require to check whether the problem is still present in Drupal 7, then write a patch and test for D7, and then backport to D6.

BeaPower’s picture

Status: Needs work » Needs review

taxonomy-hierarchy.patch queued for re-testing.

klonos’s picture

Are we absolutely sure this has 'normal' priority?

pwolanin’s picture

looks like we are still missing the test Dries wanted - let me try to write it

pwolanin’s picture

Status: Needs review » Needs work

The relations field is no longer used:

/**
 * Remove the related terms setting from vocabularies.
 *
 * This setting has not been used since Drupal 6. The {taxonomy_relations} table
 * itself is retained to allow for data to be upgraded.
 */
function taxonomy_update_7003() {
  db_drop_field('taxonomy_vocabulary', 'relations');
}
pwolanin’s picture

Status: Needs work » Needs review
StatusFileSize
new1.09 KB

Here's a 1st pass at a regression test - should have 1 fail which demonstrates that it detects the bug.

pwolanin’s picture

StatusFileSize
new1.77 KB

Here's a new patch with the test.

Status: Needs review » Needs work

The last submitted patch, 353775-preserve-hierarchy-31.patch, failed testing.

pwolanin’s picture

Status: Needs work » Needs review

#31: 353775-preserve-hierarchy-31.patch queued for re-testing.

BeaPower’s picture

Will this patch also list subcategories by default on the blocks?

pwolanin’s picture

@BeaPower - that is totally unrelated to this patch.

BeaPower’s picture

Then can you please help me, the posts Ive read similar to what I want directed me to this post. How can this be achieved? http://drupal.org/node/964970

Peter Swietoslawski’s picture

StatusFileSize
new864 bytes

Here is a backport of patch @31 to D6.

klonos’s picture

I want to help with this. Can someone please provide steps to reproduce the issue so I can test if patches resolve it?

Peter Swietoslawski’s picture

klonos for D6 you just need to:

  • edit one of a terms under given vocabulary (/admin/content/taxonomy/#VID) and set it to use multiple parents (this will change terms list to not be draggable and will set hierarchy field in vocabulary table to 2 for the relevant vocabulary)
  • edit the vocabulary page like /admin/content/taxonomy/edit/vocabulary/#VID. Then you save the page and observe hierarchy field in vocabulary table for your VID will change back to 1 and the term list page will become draggable again - this is WRONG. Patch prevents this
klonos’s picture

I am trying to test/reproduce this in 7.0, and here are my findings so far:

Behavior before patch:
a. After setting multiple parents for a term, I get this:

Notice: Undefined index: description in taxonomy_form_term_submit_build_taxonomy_term() (line 840 of /var/www/d7test/modules/taxonomy/taxonomy.admin.inc).

b. The list page is always draggable in my case, but while the field is set to '2' it simply has no 'Save' button available. Is this a known issue? If so, please point me to it, otherwise I'll file a new Usability/UX issue for that.
c. Editing and saving the vocabulary does bring back the 'Save' button (+ the 'Reset to alphabetical' button) and the hierarchy field of the taxonomy_vocabulary table changes to '0' (not '1' as mentioned in the 2nd step in Peter's repro instructions above). I don't know if this is important or not, but I thought I'd report it anyways. / note-to-self: read issue title better next time ;) /
d. Dragging a term to another place and saving the list throws this:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '5-1' for key 'PRIMARY': UPDATE {taxonomy_term_hierarchy} SET parent=:db_update_placeholder_0 WHERE (tid = :db_condition_placeholder_0) ; Array ( [:db_update_placeholder_0] => 1 [:db_condition_placeholder_0] => 5 ) in taxonomy_overview_terms_submit() (line 495 of /var/www/d7test/modules/taxonomy/taxonomy.admin.inc).

Behavior after the patch from #31 is applied* (also reset the vocab to alphabetical and no multiple parents):
a. When setting multiple parents, I still get the notice I get without the patch applied. I've filed #1015572: Notice: Undefined index description taxonomy_form_term_submit_build_taxonomy_term(), line 842 of taxonomy.admin.inc for that.
b. Still the same behavior. Be it a known/accepted behavior or not, I still think that drag handlers should not be there at all. But that's a different issue as I've said. Let me know if it is already reported.
c. Editing and saving the vocabulary does NOT bring back the 'Save' button (NOR the 'Reset to alphabetical' button) and the hierarchy field of the taxonomy_vocabulary table DOES NOT change to '0' remaining set to '2'.
d. I cannot reproduce this (since there is no 'Save' button in the list page), but if this is considered a kind of 'locked' state, then no dragging should be enabled whatsoever.

*Note: I manually applied the patch as it seems that code has shifted a few line down. Needs re-roll(?).

PS: I was not able to locate the 'relations' field in order to include this in my tests. In which table am I supposed to be looking for it?

PPS: Does this count as a proper review?

[edit: patch from #31 was used - I'll see if I can find some time to test #37 in D6 too]

klonos’s picture

I was not able to locate the 'relations' field in order to include this in my tests. In which table am I supposed to be looking for it?

...never mind, I just realized that this field is available only in D6 vocabulary table. I'll test it in D6.

klonos’s picture

Title: Vocabulary edit form resets the 'hierarchy' field to '0' and 'relations' field to '1' » Vocabulary edit form resets the 'hierarchy' field (D7) to '0' and 'relations' field (D6) to '1'

...minor title change to avoid confusion.

haopei’s picture

Wow lots of information here. Can someone point me to the one which definitely works?

I am not very familiar with patches, and patch jargon.

haysuess’s picture

None of the patches works for me. I can add terms fine, but any time I try to edit or delete one it gives me the WSOD and the Hierarchy value changes back to 1.

My workaround was this:

I created 3 dummy categories and set them up like so:

X
-XZ
Z
-XZ

XZ is a child of both X and Z, so it somehow makes the vocabulary know that it shouldn't revert to a hierarchy of 1 because XZ has 2 parents, even if I change other things.

Is there a better solution? I'd like for this not to be any issue at all :-/

xjm’s picture

Version: 7.x-dev » 8.x-dev
Status: Needs review » Needs work
Issue tags: +Needs backport to D7
stpaultim’s picture

Ok, with the encouragement of xjm I'm trying to recreate this issue in Drupal 8 core.

This is what I've done, so far.

1) I create a new Taxonomy.
2) I added two terms.
3) Then I added a third term and assigned it two "parent" terms.

At this point, all terms are "draggable." The third term is listed twice, once under each parent, and both are movable. I can add terms to the list, but I can't save any changes to the list, because once I added the third term, assigned to two parents, the SAVE button on the taxonomy list disappeared.

That doesn't look right. I'm not sure if I need to go further.

stpaultim’s picture

StatusFileSize
new39.84 KB
new43.76 KB
new39.04 KB

Again, not sure if this related to the original issues, but I've been urged to provide some screenshots. So here they are.

Created a taxonomy of locations and created three items, assigned "Wisconsin" as the parent of "Hudson." Behaved the same at both these locations:
http://monday:8082/taxonomy/term/8#overlay-context=taxonomy/term/8&overl...
http://monday:8082/admin/structure/taxonomy/locations

taxonomy issues

Then added "Minnesota" as a second parent of "Hudson" and the SAVE button disappears.

More taxonomy images

If I remove one of the parents, the SAVE button comes back.

More taxonomy images

stpaultim’s picture

StatusFileSize
new10.27 KB
new9.64 KB

Now, trying to recreate the problem:

1) Added two taxonomy terms, assigned no parents, at: "admin/structure/taxonomy/terms"
MySQL table "taxonomy_vocabulary" item "hierarchy" = 0

2) Added third taxonomy term (THREE), assigned to terms ONE and TWO as parents.
MySQL table "taxonomy_vocabulary" item "hierarchy" = 2

3) Modified taxonomy term THREE to only have ONE as its parent.
Used this page: taxonomy/term/28/edit?destination=admin/structure/taxonomy/my_terms
MySQL table "taxonomy_vocabulary" item "hierarchy" = 1

4) Added taxonomy term FOUR to have TWO as its parent.
(two terms have one parent each, no term has two parents)
MySQL table "taxonomy_vocabulary" item "hierarchy" = 1

5) Modified taxonomy term THREE to have "ROOT" as its parent.
taxonomy/term/28/edit?destination=admin/structure/taxonomy/my_terms
(one term -FOUR- still has one parent)
MySQL table "taxonomy_vocabulary" item "hierarchy" = 0

If I understand, this is bad behavior we were looking to confirm.
BUT, one more thing that may or may not be a problem.

6) Modified taxonomy term THREE to not have any parent.
taxonomy/term/28/edit?destination=admin/structure/taxonomy/my_terms
Term THREE is no longer listed here: admin/structure/taxonomy/my_terms
BUT THREE is still visible in the MySQL database table = taxonomy_term_data
(see screenshot)

taxonomy issues

Here is a shot where a parent is selected (for comparison):

taxonomy issues

This seems like it might be a potential problem? Or not?

xjm’s picture

Issue tags: +Needs tests

Thanks @stpaultim!

So the behavior is definitely still present in D8 with all manner of weirdness. @stpaultim's research above shows three different weird behaviors between the vocab edit form and the tabledrag.

The next step here is to create a new patch and some automated tests that fail with the bugs @stpaultim found. Edit: See #31 for a starting point.

xjm’s picture

Title: Vocabulary edit form resets the 'hierarchy' field (D7) to '0' and 'relations' field (D6) to '1' » Vocabulary edit form resets the 'hierarchy' field (D7/8) to '0' and 'relations' field (D6) to '1'
dags’s picture

Assigned: Unassigned » dags
dags’s picture

StatusFileSize
new1.67 KB

Reroll of #31 for changes to D8 directory structure. The patch still needs work though.

dags’s picture

Status: Needs work » Needs review
dags’s picture

StatusFileSize
new1.67 KB

Fixing a couple typos.

Status: Needs review » Needs work

The last submitted patch, 353775-preserve-hierarchy-55.patch, failed testing.

tim.plunkett’s picture

Issue tags: -Needs tests
+++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.phpundefined
@@ -92,6 +92,13 @@ class TermTest extends TaxonomyTestBase {
+    // Regression test for http://drupal.org/node/353775

Sum up the issue instead of just linking to it.

+++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.phpundefined
@@ -92,6 +92,13 @@ class TermTest extends TaxonomyTestBase {
+    // Edit the vocabulary. this should not change he hierarchy value.

This should not be lowercase, 'the' is spelled wrong.

+++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.phpundefined
@@ -92,6 +92,13 @@ class TermTest extends TaxonomyTestBase {
+    $this->assertEqual($vocabulary->hierarchy, 1, 'Vocabulary is marked as hierarchical.');

Maybe change this message to "Vocabulary is still marked as hierarchical."?

vlad.k’s picture

subscribing

roderik’s picture

A little addition to this issue... just text, no patches, sorry.

1)
There are more bugs in taxonomy.module than the ones covered in this patch.

taxonomy_check_vocabulary_hierarchy() mistakenly resets 'single hierarchy' (1) vocabularies to 'flat' (0).

This -and not the current patch- is probably what causes the issue listed in point 5 of comment #49 by @stpaultim.

The following can fix this:

@@ -575,7 +575,7 @@ function taxonomy_check_vocabulary_hierarchy($vocabulary, $changed_term) {
       $hierarchy = 2;
       break;
     }
-    elseif (count($term->parents) == 1 && !isset($term->parents[0])) {
+    elseif (count($term->parents) == 1 && !empty($term->parents[0])) {
       $hierarchy = 1;
     }
   }

(The 'isset' just does not make any sense here.)

...but this will be unnecessary if #1925638: optimize taxonomy_check_vocabulary_hierarchy() gets in, which makes taxonomy_check_vocabulary_hierarchy() faster, but gets rid of the bug as well.

2)
As far as point 6 of comment #49 goes:

'not having any parents' (as opposed to 'having "root" as parent) should be made impossible, no? Shouldn't the "Parent terms" widget be 'required'?

Anonymous’s picture

Issue summary: View changes

This is still present in Drupal 8 Alpha 11 and as today also in HEAD.

mgifford’s picture

Version: 8.0.x-dev » 8.1.x-dev
Assigned: dags » Unassigned

This still a concern in D8? Unassigned issue too.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

idebr’s picture

Title: Vocabulary edit form resets the 'hierarchy' field (D7/8) to '0' and 'relations' field (D6) to '1' » Vocabulary edit form resets the 'hierarchy' (D7) field to '0' and 'relations' field (D6) to '1'
Version: 8.8.x-dev » 7.x-dev

The hierarchy property ended up being removed in #2957381: Data model problems with Vocabulary hierarchy for Drupal 8

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.