TermStorage::loadChildren returned elements are not sorted by weight, name

Created on 20 June 2019, over 5 years ago
Updated 28 September 2023, about 1 year ago

Problem/Motivation

TermStorage::loadChildren returns not sorted children for term.
Actually it comes from TermStorage::getChildren which actually runs the EntityQuery for getting the children for the given parent.

Steps to reproduce

Build a custom Taxonomy with custom weights for its children.
Then try to to get the children for a parent - programatically.

For UI/UX:
From code ... there are no usage in core - only in tests ... but they do not check the sorting.

I noticed some usage in contrib Facets - Taxonomy hierarchy

Proposed resolution

- Fix TermStorage::getChildren but adding sorts by weight and name for the EntityQuery there.
- Test the sorting for getting the children

Remaining tasks

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

None

Original summary repoty

When I upgrade Drupal core from 8.4.6 to 8.6.16 I faced an issue in TermStorage::loadChildren.

I was using this function
:\Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadChildren($parent_term->id());
for manging the website navigation by parent client relation . But after the upgrade the order was not by weight .

Adding the API page, someone else also faced the issue: https://api.drupal.org/api/drupal/core%21modules%21taxonomy%21src%21Term...

Adding a patch to fix this by adding :" ->sort('weight', 'ASC'); to the getChildren function.

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
TaxonomyΒ  β†’

Last updated about 21 hours ago

  • Maintained by
  • πŸ‡ΊπŸ‡ΈUnited States @xjm
  • πŸ‡¬πŸ‡§United Kingdom @catch
Created by

πŸ‡ΊπŸ‡ΈUnited States rabithk

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024