Problem/Motivation
Taxonomy weight for one language often affects negatively desired order in another language.
To make all languages accessible all the time, we should be able to optionally set the weights per language.
Example:
Taxonomy for plants in English:
Pine Trees
Shrubs
Taxonomy for plants in French:
Épinettes
Arbustes
Lets say we want to put Arbustes with weight -1 for french, if we do this then Shrubs becomes -1 above Pine Trees.
This is alphabetically undesireable , there may be other reasons for setting weights differently per language.
We have provided a patch below with new automated tests that solves this.
The 'weight' property of a taxonomy term is not translatable, so you are unable to order the terms differently in each language. This makes it impossible, for example, to have the terms alphabetically sorted in each language.
If the weight property were translatable then each language could be ordered independently - a big win.
Steps to reproduce
TBD
Proposed resolution
TBD
Merge request link
6371
Remaining tasks
Feedback from MR
Issue summary completion
Change record
User interface changes
NA
API changes
NA
Data model changes
TBD
Release notes snippet
NA
Comment | File | Size | Author |
---|---|---|---|
#48 | 2931680-nr-bot.txt | 1.87 KB | needs-review-queue-bot |
Issue fork drupal-2931680
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 #2
claudiu.cristeaVery valid point!
Comment #5
volkswagenchicktagging for some upcoming collab days
Comment #8
lorenzs CreditAttribution: lorenzs at Cegeka commentedI did a rough attempt to see how feasible this would be.
See patch in attachment as a starter. Currently no tests added, some existing might fail..
We are currently testing this locally on our multilingual project but at first sight this seems to work. I'm not so familiar with core entities & translations so review definitely needed.
Currently the adapted query in loadTree (TermStorage) will only be applied on multilingual sites. Additionally we want to make this configurable by adding a config option on the level of the taxonomy to allow/disallow weights per language. This is not yet included in the patch.
The reason why this query was adapted with a subquery and alternative condition is because we want to have a fallback in case a term was not (yet) translated. In this case we just fall back to the 'default'. The subquery prevents doubles (meaning: giving back as well the default_langcode term and it's translations - which is undesirable of course).
Comment #12
joseph.olstadRerolled for 9.3.x
Comment #13
joseph.olstadComment #14
joachim CreditAttribution: joachim as a volunteer commented> This makes it impossible, for example, to have the terms alphabetically sorted in each language.
That surely makes this a bug.
Comment #15
joseph.olstadran
phpcbf --standard=Drupal core/modules/taxonomy/src/TermStorage.php
this time, removed an empty line that the test runner complained aboutComment #16
joseph.olstadComment #17
joachim CreditAttribution: joachim as a volunteer commentedWhat's the impact of the subquery on performance?
Comment #18
kriboogh CreditAttribution: kriboogh at Calibrate commentedSmall change, but I needed to update the hook number to reflect the new D9 core version. We had another patch with a 9200 update hook so the update number didn't run. since we are on 9.3, i set it to 9301.
Comment #19
joseph.olstad#17, performance cost of subquery:
good question. In what situations is the term storage loadTree method called? is this only for taxonomy term editing, browsing a vocabulary? or are there other common tasks that would invoke this method?
Comment #20
kriboogh CreditAttribution: kriboogh at Calibrate commentedThere was an issue with patch #18 when a site only has one language. The condition caused an infinite recursion. Patch #20 solves this along with a rewrite of the query replacing the subquery with a left join.
Comment #21
joachim CreditAttribution: joachim as a volunteer commented> good question. In what situations is the term storage loadTree method called?
Everywhere, by the looks of it! In forms, in the ForumManager, and also the TaxonomyIndexTid views filter.
Subqueries can usually be rewritten as a self-join, which has a much lesser performance cost. Setting to needs work based on that.
Comment #22
kriboogh CreditAttribution: kriboogh at Calibrate commented> Subqueries can usually be rewritten as a self-join, which has a much lesser performance cost. Setting to needs work based on that.
Uhu, that's what I did in #20... so needs review.
Comment #23
joachim CreditAttribution: joachim at Factorial GmbH commented@kriboogh oops, sorry!
Comment #24
ita08 CreditAttribution: ita08 commentedReroll of patch 2931680-20 for version 9.1.4
Comment #25
joseph.olstadReroll for D9.3.0-beta2
Comment #26
joachim CreditAttribution: joachim at Factorial GmbH commentedI think this is RTBC.
Comment #27
MatroskeenAfter making a quick look into the issue summary and patch, there 3 points that core committers usually ask. Let's save their time and take care of that beforehand:
1) Although the issue summary is clear, it would be really great to use the default issue template to outline some important sections: https://www.drupal.org/community/contributor-guide/reference-information...
2) It looks to me that this is rather a new feature instead of a bug. I think we should also draft a change record, what do you think? If you insist it is a bug, let's describe why :)
3) Finally, we should add a test coverage including a test for the update hook as well.
I'm adding appropriate tags and moving it back to "Needs Work".
Thanks!
Comment #28
joachim CreditAttribution: joachim at Factorial GmbH commented> If you insist it is a bug, let's describe why :)
It is a bug because on a multilingual site, taxonomy terms can't be put into alphabetical order in all languages.
> 3) Finally, we should add a test coverage including a test for the update hook as well.
I'm not sure it needs test coverage for the functionality. It's just a multilingual field. We don't have tests for the translatability of all base fields on core entities, but tests of the entity translation system in general.
I don't know about tests for the update hook though.
Comment #29
joseph.olstadI tend to agree with @joachim
not sure what difference that makes though whether it's a bug or not other than a change request, I don't think this needs one though, it should just be fixed plain and simple.
An automated test should be fairly easy to put in place ,just take the current weight test, but with translation enabled
test translated term weights , change both translated and default and make sure that weights are different for the translated term weights than the default term weights
Comment #32
mohit_aghera CreditAttribution: mohit_aghera at PreviousNext commentedAdded a test cases to validate the weight field translatibility.Initially I tried to write kernel test, however I was not able to properly work it out.
Took to functional test approach for now.
Added a test to validate the database update hook as well. Both are passing on localOops, incorrect interdiff. Uploading a fresh one.
Please ignore this patch.
Comment #33
mohit_aghera CreditAttribution: mohit_aghera at PreviousNext commentedAdded a test cases to validate the weight field translatibility.
Initially I tried to write kernel test, however I was not able to properly work it out.
Took to functional test approach for now.
Updated the correct interdiff.
Diff is taken from comment #25 only.
Comment #35
smustgrave CreditAttribution: smustgrave at Mobomo commentedRemoving the needs tests tag as they appear to have been added.
Still could use the IS update and change record so leaving the tags for those. Moving to NW for them.
Not super clear the issue
In Drupal 10 I added some terms to the tags vocabulary.
I'm able to have different orders per language.
Comment #36
joseph.olstaduploading a tests_only patch to prove that the patch 37 is needed.
Comment #37
joseph.olstadsorry this one is better
stright up reroll for 10.1.x
Comment #38
joseph.olstadComment #39
joseph.olstadIs this issue summary clear enough?
We need now a change record? or can this be skipped because it's 'optional'?
Comment #41
shalini_jha CreditAttribution: shalini_jha at QED42 for QED42 commentedI have able to Reproduce the issues in 11.x .
1) I have added dutch language (nl)
2) added same taxonomy terms as mentioned in IS.in english
3) added translation for two taxonomy term.
4) Changed weight in English and save . it is changing for both language.
applied this patch #37 , its fixed the issues and weight is changing according to language selected.
please review and let me know if you need MR for this.
Comment #42
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue.
While you are making the above changes, we recommend that you convert this patch to a merge request. Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)
Comment #44
joseph.olstadThe patch and the automated tests have been reviewed however the core maintainers will likely have their say.
Please create a change record.
Other than the change record, I believe this is ready.
Comment #45
joseph.olstadComment #46
smustgrave CreditAttribution: smustgrave at Mobomo commentedAdded some nitpicky stuff, but the update hook version should be updated.
Appears to have a phpcs issue.
Issue summary was missing standard template, got it started but left TBD for sections I can't answer not being familiar with issue.
Agree on the need for a CR
Also agree this appears close though!
Comment #47
joseph.olstadComment #48
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #49
joseph.olstadComment #50
joseph.olstadComment #51
joseph.olstadGoing out on a limb here, saying it's good.
There's a draft change request
There's passing tests
There's tests only fails
Looks good to me. Slam dunk?
We've been using a version of this solution for several years in harmony.
Comment #52
larowlanLeft some questions/comments on the MR
Comment #53
joseph.olstadHead of 11.x/10.2.x is broken right now so we'll have to re-trigger tests once that's fixed. I imagine that'll be fixed soon.https://www.drupal.org/node/3060/qa***EDIT***
nvm, look at gitlab ci instead:
https://git.drupalcode.org/issue/drupal-2931680/-/pipelines/87571
Comment #54
joseph.olstadLooks like performance profiling tests show degraded performance when testing against Postgres 14.1 . Funny that the other DB systems tested do not have any performance regression.