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

Command icon 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

dcam created an issue. See original summary.

dcam’s picture

Status: Active » Needs review

In 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.

mparker17’s picture

Title: Fix order of child terms » Nested taxonomy terms should be ordered by weight
Status: Needs review » Reviewed & tested by the community

This 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!

  • mparker17 committed d74d2a83 on 8.x-2.x authored by dcam
    Issue #3466104 by dcam: Nested taxonomy terms should be ordered by...
mparker17’s picture

Status: Reviewed & tested by the community » Fixed

I'll be making a release with this change soon! (probably today?)

dcam’s picture

No problem. I'm glad I could help out.

mparker17’s picture

Note that this change was released in sitemap-8.x-2.0-beta7.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.