Steps to reproduce:
- Enable views, taxonomy, content translation
- Enable the languages German and French
- Create a vocabulary with these terms and the corresponding translations:
- Albania / Albanien / Albanie
- Egypt / Ägypten / Égypt
- Finland / Finnland / Finlande
- Germany / Deutschland / Allemagne
- Saudi Arabia / Saudi-Arabien / Arabie saoude
- Create a view with an exposed taxonomy term filter.
- Open the view in English, German and French.
Expected ordering of the taxonomy terms:
English: Albania, Egypt, Finland, Germany, Saudi Arabia
German: Ägypten, Albanien, Deutschland, Finnland, Saudi-Arabien
French: Albanie, Allemagne, Arabie saoude, Égypt, Finlande
Actual ordering in all languages:
Egypt, Albania, Germany, Saudi Arabia, Finland
As can be seen, each term is in the first position allowed by any of its translations: Egypt by its German name, Germany and Saudi Arabia by their French names.
It seems that in the query, the terms are selected without language filtering, ordered alphabetically, and then the TIDs are de-duplicated before being passed to Term::loadMultiple.
The fix would be inserting a langcode filter into the entity query.
Comment | File | Size | Author |
---|---|---|---|
#21 | 2862533-21-taxonomy-filter-sort.patch | 1.44 KB | florianmuellerCH |
#20 | interdiff_18_20.txt | 792 bytes | anmolgoyal74 |
#20 | 2862533-20-taxonomy-filter-sort.patch | 1.99 KB | anmolgoyal74 |
#18 | 2862533-18-taxonomy-filter-sort.patch | 1.98 KB | tomasbarej |
#14 | 2862533-14-taxonomy-filter-sort.patch | 1.73 KB | florianmuellerCH |
Comments
Comment #2
cburschkaComment #3
dagmarThere is a similar issue #1821274: Add back ability to sort on vocabulary weight and name that was closed without explanation. Actually there is some relevant code at
TaxonomyIndexTid
Comment #4
cburschkaIndeed, the current approach is broken because it doesn't even present the terms correctly in a single default language. It's not like "we're in language X, but the terms are sorted by their language Y translations". Rather "all translations from languages X,Y,Z are sorted in one list, then all but the first occurrence of each term are discarded", which yields gibberish.
As the translation of each term is not acquired until later, it is impossible to apply any ordering in the entity query; the sorting has to be done in PHP on the results.
Comment #5
cburschkaI would suggest the following, but it can probably be improved on:
Comment #6
cburschkaPatch is for 8.2.7, but as far as I can tell this should still apply to 8.3.x.
Comment #8
dagmar@cburschka It will not apply to 8.3.x because array() syntax was replaced by [] syntax.
Comment #9
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedComment #10
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedRe-roll
Comment #14
florianmuellerCHRe-rolled it against 8.7
Comment #15
florianmuellerCHComment #18
tomasbarej CreditAttribution: tomasbarej commentedHere is patch version for 8.9.x
Comment #20
anmolgoyal74 CreditAttribution: anmolgoyal74 at OpenSense Labs for DrupalFit commentedUpdated the deprecated function.
Comment #21
florianmuellerCHRe-Rolled on Drupal 9.1.10.
Comment #23
JeroenTI’m closing this as a duplicate of #2577179: Views Taxonomy dropdown filter is not ordered alphabetically.
Comment #24
JeroenT