Problem/Motivation
On a multilingual website:
- Create an article with a tag, for example in english
- Translate the article in french and do not associate the french version with the tag.
- Go to the tag page in english
- See your article in english: OK, normal
- Go to the tag page in french
- See your article in french: KO, the french version of the article is not associated with the tag
The problem is due to the taxonomy_index table, the langcode of the node is not stored. So when the contextual filter "Content: Has taxonomy term ID" make a relationship on the table, it includes the node in all the languages.
Proposed resolution
I don't know how the clean way to solve this and as I need something working quickly I made a workaround. I will upload a patch (with a hook_update_n starting at 8300 to not be incompatible with further merged hook_update_n).
The idea is to add a "langcode" column to store the langcode of the node in which the taxonomy term is referenced.
Then adding a new view filter on this column to be able to filter the results to avoid duplication.
Remaining tasks
- Code / idea review
- Needs tests
- Needs proper update path
User interface changes
A new view filter is created: "Taxonomy term: Node language"
Data model changes
Column "langcode" added to taxonomy_index and "langcode" added to the primary key and the ndexes of the table.
| Comment | File | Size | Author |
|---|---|---|---|
| #148 | 2889486-148.patch | 19.45 KB | evilargest |
| #144 | 2889486-v17-144.patch | 19.88 KB | evilargest |
| #136 | 2889486-nr-bot.txt | 90 bytes | needs-review-queue-bot |
| #134 | 2889486-nr-bot.txt | 90 bytes | needs-review-queue-bot |
| #127 | 2889486-10.3-127.patch | 20.71 KB | kriboogh |
Issue fork drupal-2889486
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
grimreaperHere is the patch.
Comment #4
grimreaperRework patch in case of the database column already exists.
Comment #5
grimreaperIt seems that the update of existing tables was not ok.
Comment #6
yogeshmpawarTriggering test bots.
Comment #10
mariiadeny commentedComment #11
mariiadeny commentedComment #12
andypostComment #13
andypostSchema & upgrade looks finished, now it needs tests to prove the bug category
Comment #14
borisson_Setting back to needs work based on #13.
Comment #17
belazHi guys,
Test in wip,
Method to be added to
core/modules/taxonomy/tests/src/Functional/TermLanguageTest.phpIn team with @qudec
Comment #18
andypostComment #19
vacho commentedPatch rerolled.
Comment #20
vacho commentedComment #22
grimreaperHello,
Here is a patch that only adds a test to highlight the problem.
Unfortunately I can't make the test fails at the expected step because the node is not appearing on the taxonomy term page and I can't figure out why.
Comment #23
grimreaperOk,
I found a better way to implement the tests. In core/modules/taxonomy/tests/src/Functional/Views/TaxonomyTermViewTest.php, there is already a dedicated test class that I didn't see.
Now I need to discuss with the maintainer on how he/she wants the tests to be implemented to introduce the new views filter plugin.
Comment #25
lendudethis updates the schema, but do we also need an update for al existing references? or can they be just left blank?
this seems wrong, it should just be an empty string
Comment #26
grimreaperIn addition to @Lendude previous comment, and saw with him.
TODO: Fix for multiple translation deletion and test coverage on that.
TODO: post update hook for settings values. Batched hook calling taxonomy_delete_node_index() then taxonomy_build_node_index() for each node.
Also applying the new contextual filter on new websites. Not coding update hook to add the new contextual filter. A change record will be done to inform and that will be ok.
I will try to do that this week.
Comment #27
grimreaperSharing my WIP.
Multiple translation deletion: Still TODO, has I just thought that now it is deleting for all translations even if you remove only one...
New filter added to the view on installation.
Still needs test and update hook.
Comment #28
grimreaperAlmost done.
TODO: Tests for hook_update_N and tests for hook_post_update_NAME.
Comment #29
grimreaperHello,
I have something OK, but as for #2888320-53: Add support for plural in Views Global result summary plugin I have the update path tests not working locally.
Comment #31
rachel_norfolkretagging
Comment #32
grimreaperUpdate test are failing locally for me but at another place.
Let's see if testbot is happy with this change.
Comment #33
grimreaperTests are green! \o/
Comment #34
lendudeReally nice work!
Update number will need to be updated to _88*
No need to drop it first, addIndex drops it if it exists
Is this needed? We aren't updating the entity are we?
"Since taxonomy_node_update() will handle the deletions of specific translations, we only need to handle the case where the whole node is deleted."
Something like that maybe?
Either use \Drupal:: or use $this->container, but let's not mix them in the same test.
The only remaining concern that I have is that doing updates for all nodes can be pretty heavy for some sites, but since we are only rebuilding a sub table here it might not be so bad. Also, don't see another way to prevent this being necessary.
Comment #35
grimreaperThanks @Lendude for the review!
1: Ok, _8801 or _8901? As the issue now targets 8.9.x-dev
2: Done
3: You are right I think. I have removed the lines, let's see the tests results
4: Done
5: Done
Comment #36
andersen_ti commentedfix on batch for post_update: incorrect start range for the query.
Comment #39
nikitagupta commentedComment #40
nikitagupta commentedComment #41
aleevasTrying to fix failed test
Comment #43
kriboogh commented#41 works (D8.9.1)
Comment #44
mayurjadhav commentedComment #45
mayurjadhav commentedComment #46
tanubansal commentedIssue is still there. Please update the patch for 9.1
Comment #48
grimreaperHello,
Trying to push it forward during DrupalCon Europe 2020.
First I will see if update is needed regarding Drupal 9.
Comment #49
grimreaperRebasing patch from comment 35.
Conflict in taxonomy.install file due to #3087644: Remove Drupal 8 updates up to and including 88**.
I skip patch from comment 41 because the interdiff file makes me feel that the patch is not ok.
I don't understand why the change in comment 36 is needed but the change is small so I can give a look. But tests in 36 are red and green in 35.
Launching automated tests on 9.2.x.
Comment #51
grimreaperTrying to make automated tests ok.
It seems that now, the index is already created and update test was referencing a file no more existing.
Comment #52
grimreaperComment #54
grimreaperComment #56
grimreaperIt should be ok now.
And from the previous patch.
I don't know if it has a real effect but at least after that the update system is happy.
Comment #57
jungleJust a general review.
2 CS violations have to be fixed.
Could use
dirname(__DIR__, 5) .to replace__DIR__ . '/../../../../..;Comment #58
grimreaperHello,
Thanks a lot @jungle for the review, nice catches!
CS violations fixed.
About
__DIR__ . '/../../../../.., ok, I prefer keeping it that way for the moment because most of the rest of the codebase is that way. I don't know ifdirname(__DIR__, 5)is the new standard.Looking at other usages in core's codebase, I realized it is a protected method, so updating it.
Thanks for the review.
Comment #59
lendudeTalked a little about it with @catch on Slack and lets see if we can't make this a little less heavy than doing updates on all nodes, if possible.
Does this work correctly? nid 50 doesn't need to be the 50th record, shouldn't it use a condition like "> $current_node" and not a range?
And can we find a way to limit the update to just nodes that currently have an entry in the index? It's not like we expect new nodes to be added to it I think?
Comment #60
grimreaperHello,
Thanks @Lendude for the reply.
I have retested the current behavior without the patch. There are entries in taxonomy_index has soon as at least one translation has a taxonomy_term, so yes, we can limit this to nodes with entries in this table. I will rework the update accordingly.
I think you are correct, I miss used the range. I will keep it to ensure 50 nodes are treated per batch, but will rely on a condition.
Comment #61
grimreaperNew patch and interdiff to take comment 59 review into account.
Comment #62
catchLet's add an explicit order by here.
Also range(NULL, $limit) removes any range from the query, it doesn't make it a LIMIT query.
Instead of storing $current_node as a node ID, can increment $start and $limit by 50 each time and remove the condition.
It should also use $settings['entity_update_batch_size'] rather than hardcoding 50.
Comment #63
grimreaperThanks @catch for the review.
Here is the new patch fixing the points.
Comment #64
grimreaperComment #65
abhijith s commentedApplied patch #63 and its not working.The non referenced translated nodes are still showing in the list.
Comment #66
grimreaperWhat steps did you do to test?
Because the new views filter needs to be applied manually for the patch to have an effect.
Also maybe this is a criteria of "needs change record"?
Comment #67
sokru commentedAdded "Needs change record" because:
- Fox existing sites one needs to manually update configurations to make use of this feature.
Changed to "Needs work" because one is not able to set views filter via UI.

- If importing manually patched
views.view.taxonomy_term.ymlfile the filter works fine. But if one deletes it, its not possible to add it back.Comment #68
grimreaperWorking on it.
Comment #69
grimreaperSo, I wonder how tests from comment 65 and 67 had been done because here are the steps I have just done and it is OK.
I have started from a fresh standard install from 9.2.x-dev and I obtain this results which are the current behavior.
Both articles are displayed in both languages.
- Then applying patch from comment 63.
- Applying database updates,
- Clearing cache
- Editing the view
I can add the new filter.
Then the result :
I will prepare the change record.
Comment #70
grimreaperComment #71
grimreaperChange record created https://www.drupal.org/node/3195569.
Needs review.
Comment #72
ericdsd commentedComment #73
sokru commentedI used following steps:
1. Clone drupal/core, git checkout 9.2.x
2. composer install
3. php core/scripts/drupal quick-start standard
4. Apply the patch.
5. Run update.php and clear Drupal cache.
6. Manually add filter according to images on #69. Save view.
7. Go to
/admin/config/development/configuration/single/export8. See how filter value is different from patch:
UI:
'***LANGUAGE_language_interface***': '***LANGUAGE_language_interface***'vs.
Patch:
'***LANGUAGE_language_content***': '***LANGUAGE_language_content***'If applying the patch before the site install. The views filter options look like:


vs.
One in #69:
It's missing "Content language selected for page" option.
Edit: Copy-paste error on 8.
Comment #74
grimreaperOk, I understand now comment 67.
Checking.
Comment #75
grimreaperSo the option only appears when on /admin/config/regional/language/detection, the option "Customize Content language detection to differ from Interface text language detection settings" is checked.
I should have had this option available when making the patch...
I will update the patch.
Comment #76
grimreaperOk, I know why it is ***LANGUAGE_language_content*** and not ***LANGUAGE_language_interface***.
Because in the other existing filter "Content: Translation language" it is ***LANGUAGE_language_content***: https://git.drupalcode.org/project/drupal/-/blob/9.2.x/core/modules/taxo...
And that seems to be ok for existing config.
Comment #77
rachel_norfolkJust doing a little tag tidying. Nice work everyone!!
Comment #78
liber_tComment #79
catchFound a couple of issues, overall looks pretty good although I need to review the logic and update a bit more
Is this the node langcode or the translation langcode, or both?
The index should be checked for performance - is this still the best order? Usually queries are ordered by sticky and created, so I woul dexpect it to be tid, status, langcode, sticky, created.
non-administrators
We should refer to the languages by name rather than langcode in the comments I think.
Same here.
'one of its languages'
Should be 'does not reference'
Comment #80
dwwThis fixes everything from #79 except the initial point #1. I'm not sure if it's node or translation langcode. ;) Haven't studied all this closely. Also haven't closely reviewed the rest of the patch. But all of @catch's concerns seem legit.
I didn't test the performance of the index, but I agree langcode should come before sticky + created (filter before sort).
Thanks,
-Derek
Comment #81
dwwComment #82
grimreaperHello,
For point 1:
Langcode of the node and the translations.
Thanks @dww for fixing the other points.
Comment #83
dww@Grimreaper: Thanks for clarifying. Updating the DB schema definition comment accordingly. Hope this is agreeable.
Comment #85
kriboogh commentedPatch #83 doesn't apply to 9.2.0, so I re-roll against 9.2.0 tag.
Comment #86
mschudders commentedReroll for 9.2.0 working patch.
Comment #88
dubey.surbhit commentedReroll patch for 9.3.x and Fixed the fails of #86
Comment #89
dubey.surbhit commentedFixed the custom command fails
Comment #90
dubey.surbhit commentedFixed the custom command fail error.
Comment #91
dubey.surbhit commentedAdded interdiff
Comment #92
mschudders commentedreroll for 9.3.x
Comment #93
mschudders commentedreroll for 9.2.5 (I hope)
Comment #94
mschudders commentedtest against latest 9.2.x
works on 9.2.5
Comment #96
mschudders commentedreroll for 9.3.0
Comment #97
mschudders commentedpatch was empty for some reason
Comment #101
vsujeetkumar commentedReroll patch created for 9.5.x, Please have a look.
Comment #102
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch 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 #103
ameymudras commentedRerolling for 10.x, couldn't generate an inderdiff
Comment #104
borisson_Both phpstan and phpcs are unhappy about the latest patch.
Comment #105
anchal_gupta commentedFixed CCF.
Comment #106
anchal_gupta commentedComment #107
borisson_Well no, it still fails.
Please run the script locally before using the drupal.org resources.
core/scripts/dev/commit-code-check.sh --drupalciComment #108
_pratik_Comment #109
tanuj. commentedAdding a reroll patch for 10.1.x and fixing all CCF issues and some other phpcs issues.
Comment #110
tanuj. commentedComment #111
_pratik_Comment #112
smustgrave commentedRemoving credit for #101, 103, 105, 108, 109, and 111 for the bad rerolls. It's expected to check your patches before uploading
You can check for build errors make sure to run
./core/scripts/dev/commit-code-check.shbefore uploading a patch to make sure there are no issues with code formatting. see https://www.drupal.org/docs/develop/development-tools/running-core-devel...Also some were missing interdiffs and none mentioning how the patch no longer applies per the new policy. The file sizes fluctuates why is that?
Honestly next reroll should start at 97
Comment #114
leo liao commentedSupport for 9.5.x based on #111.
Then I made some adjustments, and when both translation and Content Moderation were enabled in the site, an exception occurred.
Steps, 1 Add node in en language, and publish en language.
2 Add the translation of ja language for it, but do not publish ja language.
At this point there will be no information about the language in the taxonomy_index table.
It cannot be displayed in the view.
This is considered an unusual error on our site. Published languages should be visible to anonymous users.
Unpublished languages may be checked in the normal workflow, it cannot affect the normal published display.
Comment #115
leo liao commentedfixed test.
Comment #116
leo liao commentedFollowing the advice from #112, from #97, that seems more reasonable.
Also, this is only in 9.5.x.
10.x will be considered in the next few months.
Comment #117
leo liao commentedInfinite loop updb.
Comment #118
gauravvvv commentedFixed CCF failure, added interdiff for same
Comment #119
impol commentedRe-rolled patch from #118 for 10.2.x
Comment #120
sourabhjainFixed CCF failure in #119, added interdiff for same
Comment #121
sumit saini commentedPatch in #120 is missing a use statement for Node class.
Updated patch in #120 to fix it. (created for 10.2.x)
Comment #124
kriboogh commentedAdd patch for MR!7968.
Fixed phpcs and tests.
Comment #126
kriboogh commentedAdded MR for roll-back to 10.3 and patch.
Comment #127
kriboogh commentedFixed mysql issue with primary key creation on 10.3
Comment #128
smustgrave commentedBefore anyone reviews can the MRs and patches be cleaned up. Not sure which MR is to be reviewed the most recent one is for 10.3 but should be against 11.x but don't want to make that assumption. Also patches should be hidden.
Comment #129
kriboogh commentedMR!9023 is for 10.3 (patch 127)
MR!7968 is for 11 (patch 124)
Comment #130
smustgrave commentedLeft some comments on MR.
Comment #132
shalini_jha commentedI have updated the code based on PR feedback and fixed the pipeline for the failing test. moving this to NR.
Kindly review.
Comment #133
sagarmohite0031 commentedHello,
MR applied successfully, Both articles are displayed in both languages.
Also can add filter.
Check attachments-
Comment #134
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. 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 #135
shalini_jha commentedComment #136
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. 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 #137
shalini_jha commentedComment #139
shalini_jha commentedRebased & fixed conflicts . Moving back to review.
Comment #140
asawari commentedHi,
Test status - Pass
Issue can be reproduced. Patch applied successfully and issue looks fixed.
Verified on Drupal 11.x- dev
Testing steps-
- Create an article with a tag, for example in english
- Translate the article in french and do not associate the french version with the tag.
- Go to the tag page in english
- See your article in english: OK, normal
- Go to the tag page in french
- See your article in french: the french version of the article is not associated with the tag
Also observed that,A new view filter is created: "Taxonomy term: Node language"
Attaching screenshots for reference.
RTBC+1
Comment #142
smustgrave commentedLeft comments on MR, thanks for keeping it going!
Comment #143
shalini_jha commentedThank you for the review and feedback :)
I’ve addressed one of the points. Regarding the hook_update_N test coverage, I haven’t worked on this type of test before, so it is still pending. I’ll try to find a solution for it.
Comment #144
evilargest commentedCreated a patch from the latest changes; works fine on 11.2.4
Comment #146
mparker17I needed this patch for a Drupal 10.4 site, so I created branch
2889486-has-taxonomy-term-10.4in the issue fork (but haven't created a merge request).Attaching a patch of the changes. I just rebased so there is no interdiff.
Comment #147
swilmes commentedI have an issue that I'm not sure fits in this ticket or not, but if it does, the patch doesn't seem to fix. I have a view of Items, and the Item content type has a "Category" taxonomy. So then I have
Item 1 in language A is tagged with Category "foo"
Item 1 in language B is tagged with Category "bar"
In the view, I have a contextual filter "Content: Has taxonomy term ID (with depth) (Default: Raw value from URL)" So that when I'm on the "foo" term page, I should see Item 1 returned if I'm in the A langcode. This is working, but the item still shows in the "bar" term page in the A langcode as well.
I've applied the patch, added a relationship to the term referenced, and then added the filter
(field_item_categories: Taxonomy term) Taxonomy term: Node language (= Interface text language selected for page)
And the item still shows when it shouldn't. I've tried with and without the relationship. Is this the same issue, or with it being a content view and not a taxonomy view is it different?
Comment #148
evilargest commentedReroll of #144 for 11.3.1