Problem/Motivation
MainController::listVocabularies(), which renders the vocabulary list at admin/structure/taxonomy_manager/voc, loads vocabularies with the following code, with no sorting applied at all.
$vocabularies = $this->entityTypeManager()->getStorage('taxonomy_vocabulary')->loadMultiple();
foreach ($vocabularies as $vocabulary) {
// …
}
loadMultiple() for a config entity storage returns entities in the order the config storage lists them, which in practice is alphabetical by machine name (entity ID), not by the human-readable label. On a site with more than a handful of vocabularies whose machine names don't happen to match their labels' order, the list looks essentially random to an editor, even though it actually is sorted — just on a key nobody sees.
Steps to reproduce
- Create (or use existing) vocabularies whose machine name doesn't sort the same way as their label, e.g. machine name references (label "Références") next to machine name object (label "Objet"): object sorts before references by machine name, but "Objet" sorts after "Références" alphabetically.
- Go to admin/structure/taxonomy_manager/voc.
- Observe the vocabularies are listed in machine-name order, not label order.
Proposed resolution
Sort $vocabularies by label before building the table. Note: a plain strnatcasecmp() on the raw label is not enough on its own for languages with accented characters (a byte-wise comparison sorts any accented letter after 'z', e.g. "Série" would sort after "Sujet d'image" instead of before it) — the attached patch folds common Latin accents to their base letter before comparing, since the intl/Collator extension can't be assumed to be available on every hosting environment.
Patch
See taxonomy_manager-vocabulary-list-sort.patch (applies cleanly to 2.0.23, -p1 from the module root).
| Comment | File | Size | Author |
|---|---|---|---|
| taxonomy_manager-vocabulary-list-sort.patch | 1.58 KB | stéphane lojkine |
Comments
Comment #2
avpaderno