Problem/Motivation
If you have a hierarchical vocabulary, the top-level terms appear in the order that they are weighted in the term list. But child terms appear in order according to their Term IDs. The cause of this is the use of loadTree() versus loadChildren(). loadTree() uses an entity query that orders by weight. loadChildren() doesn't order the results, so it will default to ordering the results by Term ID.
The end result is a confusing experience for content managers. Because they see the top-level terms ordered by the weight that they set. But then the child terms don't do the same thing. They may even think that their new terms are missing from the sitemap if the list is long enough and they didn't scroll down.
Steps to reproduce
- Make a vocabulary with three terms.
- Make terms two and three children of the first.
- Put term three in the order above term two.
- Configure the sitemap to display the vocabulary.
- View the sitemap.
Expected result: The sitemap will show terms two and three as children of term one. Term three will be listed before term two.
Actual result: Term two will be listed before term three.
Proposed resolution
Only use loadTree() to load children since it respects the term weights.
Remaining tasks
Review the patch.
User interface changes
Hierarchical vocabulary sitemaps will have their orders changed.
Issue fork sitemap-3466104
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
dcam commentedIn the end all I really did was simplify the code. I wasn't sure if this would break something, but all the tests passed on my local.
Comment #4
mparker17This looks good to me!
Thank you very much for including a test to demonstrate the problem: it made reviewing the change much easier for me as a maintainer, and much faster! I wish more people would include tests in their merge requests!
Comment #6
mparker17I'll be making a release with this change soon! (probably today?)
Comment #7
dcam commentedNo problem. I'm glad I could help out.
Comment #8
mparker17Note that this change was released in sitemap-8.x-2.0-beta7.