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

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

CommentFileSizeAuthor
#48 2931680-nr-bot.txt1.87 KBneeds-review-queue-bot
#37 2931680-38.patch8.12 KBjoseph.olstad
#37 tests_only_expect_failure-2931680-38.patch3.47 KBjoseph.olstad
#36 tests_only_expect_failure-2931680-37.patch1.7 KBjoseph.olstad
#33 interdiff-2931680-33-25.txt3.46 KBmohit_aghera
#33 2931680-33.patch8.11 KBmohit_aghera
#32 interdiff-2931680-32-25.txt3.46 KBmohit_aghera
#32 2931680-32.patch22.39 KBmohit_aghera
#25 interdiff_20_to_25-2931680-25.txt1.28 KBjoseph.olstad
#25 D93x-2931680-25-reroll.patch4.64 KBjoseph.olstad
#24 make-taxonomy-weight-translatable-2931680-20-reroll.patch4.53 KBita08
#20 make-taxonomy-weight-translatable-2931680-20.patch4.54 KBkriboogh
#18 make-taxonomy-weight-translatable-2931680-18.patch4.1 KBkriboogh
#15 make-taxonomy-weight-translatable-2931680-15.patch4.1 KBjoseph.olstad
#12 make-taxonomy-weight-translatable-2931680-12.patch4.1 KBjoseph.olstad
#8 make-taxonomy-weight-translatable-2931680-8.patch4.18 KBlorenzs

Issue fork drupal-2931680

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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nicrodgers created an issue. See original summary.

claudiu.cristea’s picture

Very valid point!

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

volkswagenchick’s picture

Issue tags: +fldc19, +dcnj19, +sfdug

tagging for some upcoming collab days

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

lorenzs’s picture

I 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).

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

joseph.olstad’s picture

joseph.olstad’s picture

joachim’s picture

Category: Feature request » Bug report

> This makes it impossible, for example, to have the terms alphabetically sorted in each language.

That surely makes this a bug.

joseph.olstad’s picture

ran phpcbf --standard=Drupal core/modules/taxonomy/src/TermStorage.php this time, removed an empty line that the test runner complained about

joseph.olstad’s picture

Issue tags: -fldc19, -dcnj19
joachim’s picture

+++ b/core/modules/taxonomy/src/TermStorage.php
@@ -230,11 +231,37 @@ public function loadTree($vid, $parent = 0, $max_depth = NULL, $load_entities =
+          // Subquery to prevent doubles in default_langcode fallback situation:

What's the impact of the subquery on performance?

kriboogh’s picture

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

joseph.olstad’s picture

#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?

kriboogh’s picture

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

joachim’s picture

Status: Needs review » Needs work

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

kriboogh’s picture

Status: Needs work » Needs review

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

joachim’s picture

@kriboogh oops, sorry!

joseph.olstad’s picture

joachim’s picture

Status: Needs review » Reviewed & tested by the community

I think this is RTBC.

Matroskeen’s picture

Category: Bug report » Feature request
Status: Reviewed & tested by the community » Needs work
Issue tags: +Bug Smash Initiative, +Needs issue summary update, +Needs tests, +Needs change record

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

joachim’s picture

Category: Feature request » Bug report

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

joseph.olstad’s picture

I 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

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mohit_aghera’s picture

Status: Needs work » Needs review
FileSize
22.39 KB
3.46 KB

Added 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 local

Oops, incorrect interdiff. Uploading a fresh one.
Please ignore this patch.

mohit_aghera’s picture

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

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: -Needs tests +Needs Review Queue Initiative

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

joseph.olstad’s picture

uploading a tests_only patch to prove that the patch 37 is needed.

joseph.olstad’s picture

sorry this one is better

stright up reroll for 10.1.x

joseph.olstad’s picture

Issue summary: View changes
joseph.olstad’s picture

Is this issue summary clear enough?

We need now a change record? or can this be skipped because it's 'optional'?

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

shalini_jha’s picture

Status: Needs work » Needs review

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

needs-review-queue-bot’s picture

Status: Needs review » Needs work

The 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.)

joseph.olstad’s picture

Status: Needs work » Needs review

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

smustgrave’s picture

Issue summary: View changes
Status: Needs review » Needs work

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

joseph.olstad’s picture

Status: Needs work » Needs review
needs-review-queue-bot’s picture

Status: Needs review » Needs work
FileSize
1.87 KB

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

joseph.olstad’s picture

Status: Needs work » Needs review
joseph.olstad’s picture

Issue tags: -Needs change record
joseph.olstad’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs Review Queue Initiative

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

larowlan’s picture

Status: Reviewed & tested by the community » Needs work

Left some questions/comments on the MR

joseph.olstad’s picture

Head 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

joseph.olstad’s picture

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

    There were 3 failures:
    
    1)
    Drupal\Tests\standard\FunctionalJavascript\StandardPerformanceTest::testAnonymous
    Failed asserting that 67 is identical to 66.
    
    /builds/issue/drupal-2931680/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:121
    /builds/issue/drupal-2931680/vendor/phpunit/phpunit/src/Framework/Constraint/IsIdentical.php:79
    /builds/issue/drupal-2931680/core/profiles/standard/tests/src/FunctionalJavascript/StandardPerformanceTest.php:58
    /builds/issue/drupal-2931680/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
    
    2)
    Drupal\Tests\standard\FunctionalJavascript\StandardPerformanceTest::testLogin
    Failed asserting that 41 is identical to 38.
    
    /builds/issue/drupal-2931680/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:121
    /builds/issue/drupal-2931680/vendor/phpunit/phpunit/src/Framework/Constraint/IsIdentical.php:79
    /builds/issue/drupal-2931680/core/profiles/standard/tests/src/FunctionalJavascript/StandardPerformanceTest.php:108
    /builds/issue/drupal-2931680/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
    
    3)
    Drupal\Tests\standard\FunctionalJavascript\StandardPerformanceTest::testLoginBlock
    Failed asserting that 50 is identical to 47.
    
    /builds/issue/drupal-2931680/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:121
    /builds/issue/drupal-2931680/vendor/phpunit/phpunit/src/Framework/Constraint/IsIdentical.php:79
    /builds/issue/drupal-2931680/core/profiles/standard/tests/src/FunctionalJavascript/StandardPerformanceTest.php:138
    /builds/issue/drupal-2931680/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
    
    FAILURES!
    Tests: 3, Assertions: 13, Failures: 3.