Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
If a term is a child term then it is not possible not move it out to the root level. This is a regression from Drupal 7.
Example on the admin/structure/taxonomy/manage/tags page:
What works: moving terms as children under other terms.
What does not work: moving a term back to the root level, so that it does not have parents.
Comment | File | Size | Author |
---|---|---|---|
#17 | interdiff.txt | 1.45 KB | plopesc |
#17 | term-listing-2049121-17.patch | 5.1 KB | plopesc |
#17 | term-listing-2049121-17-test-only.patch | 1.66 KB | plopesc |
#13 | term-listing-2049121-13.patch | 4.7 KB | plopesc |
#6 | term-listing-2049121-6.patch | 1.97 KB | plopesc |
Comments
Comment #1
klausiHere is a test case that demonstrates the bug, so this will fail on the testbot.
Comment #3
larowlanGood catch
Comment #4
plopescHello
I've been digging in this issue and I think that the problem is related with parent field.
In line 370 of taxonomy.admin.inc file you can find:
Problem is that $term->parent->value is always empty, then when it try to compare, it doesn't update that value when level is root.
However, $term->weight->value is retrieved from DB without any problem.
I hope this can help.
Comment #5
effulgentsia CreditAttribution: effulgentsia commentedI haven't tested to see if this is still the case, but if it's a regression from D7, that makes it a critical.
Comment #6
plopescHello
The bug persists.
After more digging,
$term->parent->value
is NULL by default for all the terms after entity_load(). Not sure if this is the expected behavior or not.Attaching patch that fixes the bug, maybe someone could find a better approach if the parent value should be loaded.
Regards.
Comment #10
plopesc6: term-listing-2049121-6.patch queued for re-testing.
Comment #12
plopescDebugging session after, I think we are next to the root of the problem...
taxonomy_get_tree function doc says:
but code in
OverviewTerms
class expects the parents in$term->parent
.It worked until now because
$term->parent
is always NULL in this environment and comparison works for numeric values, but not for empty value when term is moved to the vocabulary root.Now, I think there are wo options now:
OverviewTerms
class to expect$term->parents
array instead of$term->parent
property.taxonomy_get_tree
logic to return$term->parent
instead of$term->parents
and modify all the code that currently expects the parents array.Here, attaching patch modifying
OverviewTest
classComment #13
plopescHere is the patch.
Not including test-only file given that is the same as #1 and #6.
Regards
Comment #14
BerdirYeah, I broke this with the Entity Field API conversion. Fix looks ok to me, there are other issues to improve the parent handling, let's just fix the bug here.
Wondering if we should also check the parents through the API, with the taxonomy_get_parents() function? (or if that is a service now, that)
Comment #15
plopescHello
Are you suggesting to load parents using
taxonomy_get_parents()
instead of the parents property returned bytaxonomy_get_tree()
?It could imply some db_queries which are maybe not necessary?
Maybe I'm missing something...
Regards.
Comment #16
BerdirOnly in the test, to make sure that the returned parent information is correct.
You're only assertion right now is a assertNoPattern() on a rather arbitrary html tag, things like that often break when the HTML changes. Explicit assertions are almost always better than something implicit.
Comment #17
plopescOh sure!
I thought you were talking about the overview terms page logic :)
Here are test improved.
Regards
Comment #19
BerdirThanks, that looks better. Would have been enough to just empty the static cache of that specific function, but it will be emptied anyway in tearDown().
Comment #20
catchYes this looks great. Committed/pushed to 8.x, thanks!
Comment #21
Yorgg CreditAttribution: Yorgg commentedThe test may have failed but #17th patch worked at least until the fourth level of taxonomy hierarchy.