Problem/Motivation

On a multilingual website:

  1. Create an article with a tag, for example in english
  2. Translate the article in french and do not associate the french version with the tag.
  3. Go to the tag page in english
  4. See your article in english: OK, normal
  5. Go to the tag page in french
  6. 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

  1. Code / idea review
  2. Needs tests
  3. 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.

CommentFileSizeAuthor
#148 2889486-148.patch19.45 KBevilargest
#146 2889486-146--for-10-4.patch20.26 KBmparker17
#144 2889486-v17-144.patch19.88 KBevilargest
#140 Filter.png33.2 KBasawari
#140 AfterPAtchfrench.png33.68 KBasawari
#140 AfterPatchEN.png29.46 KBasawari
#136 2889486-nr-bot.txt90 bytesneeds-review-queue-bot
#134 2889486-nr-bot.txt90 bytesneeds-review-queue-bot
#133 Screenshot from 2024-11-06 23-35-06.png157.84 KBsagarmohite0031
#133 tag-french-fr-DrupalPod-11-06-2024_11_37_PM.png116.66 KBsagarmohite0031
#133 tag-french-DrupalPod-11-06-2024_11_37_PM.png140.97 KBsagarmohite0031
#127 2889486-10.3-127.patch20.71 KBkriboogh
#127 interdiff_10.3-124-127.txt1.76 KBkriboogh
#126 2889486-10.3-124.patch20.85 KBkriboogh
#124 interdiff_121-124.txt12.84 KBkriboogh
#124 2889486-124.patch20.49 KBkriboogh
#121 interdiff_120-121.txt1.89 KBsumit saini
#121 2889486-121.patch20.26 KBsumit saini
#120 interdiff_119-120.txt2.49 KBsourabhjain
#120 2889486-120.patch20.09 KBsourabhjain
#119 2889486-119.patch19.16 KBimpol
#118 interdiff-117_118.txt1.16 KBgauravvvv
#118 2889486-118.patch24.4 KBgauravvvv
#117 2889486-97-117.patch24.4 KBleo liao
#116 2889486-97-116.patch24.15 KBleo liao
#115 2889486-113-115.patch30.59 KBleo liao
#114 2889486-113.patch30.57 KBleo liao
#111 2889486-110.patch31.18 KB_pratik_
#109 interdiff_103-109.txt2.71 KBtanuj.
#109 2889486-109.patch24.7 KBtanuj.
#108 interdiff_2889486_105-108.txt10.38 KB_pratik_
#108 2889486-108.patch30.72 KB_pratik_
#105 interdiff-2889486-103_105.txt518 bytesanchal_gupta
#105 2889486-105.patch22.86 KBanchal_gupta
#103 2889486-103.patch22.75 KBameymudras
#102 2889486-nr-bot.txt86 bytesneeds-review-queue-bot
#101 interdiff_92-101.txt1.03 KBvsujeetkumar
#101 2889486_101.patch22.91 KBvsujeetkumar
#97 2889486_95.patch22.9 KBmschudders
#96 2889486_95.patch0 bytesmschudders
#94 2889486_93.patch22.86 KBmschudders
#93 2889486_93.patch22.86 KBmschudders
#92 2889486_92.patch22.89 KBmschudders
#91 interdiff_89-90.txt949 bytesdubey.surbhit
#90 2889486-90.patch22.96 KBdubey.surbhit
#89 interdiff_88-89.txt302 bytesdubey.surbhit
#89 2889486-89.patch23.31 KBdubey.surbhit
#88 2889486-88.patch23.31 KBdubey.surbhit
#86 2889486-86.patch22.92 KBmschudders
#85 2889486-85-920.patch12.32 KBkriboogh
#83 2889486.80_83.interdiff.txt523 bytesdww
#83 2889486-83.patch22.64 KBdww
#80 2889486.63_80.interdiff.txt3.41 KBdww
#80 2889486-80.patch22.62 KBdww
#73 2889486-site-install.png158.49 KBsokru
#69 Capture d’écran de 2021-01-30 14-01-22.png95.2 KBgrimreaper
#69 Capture d’écran de 2021-01-30 14-01-21.png102.19 KBgrimreaper
#69 Capture d’écran de 2021-01-30 14-00-56.png168.62 KBgrimreaper
#69 Capture d’écran de 2021-01-30 14-00-48.png206.79 KBgrimreaper
#69 Capture d’écran de 2021-01-30 13-58-19.png95.97 KBgrimreaper
#69 Capture d’écran de 2021-01-30 13-58-17.png94.91 KBgrimreaper
#67 Screenshot 2021-01-26 at 13.06.56.png94.64 KBsokru
#65 2889486-63-patch_applied.png45.52 KBabhijith s
#63 interdiff-2889486-61-63.txt1.53 KBgrimreaper
#63 drupal-has_taxonomy_term_language-2889486-63.patch23.76 KBgrimreaper
#61 interdiff-2889486-58-61.txt1.61 KBgrimreaper
#61 drupal-has_taxonomy_term_language-2889486-61.patch23.67 KBgrimreaper
#58 interdiff-2889486-56-58.txt1.79 KBgrimreaper
#58 drupal-has_taxonomy_term_language-2889486-58.patch23.49 KBgrimreaper
#56 interdiff-2889486-54-56.txt1.86 KBgrimreaper
#56 drupal-has_taxonomy_term_language-2889486-56.patch23.7 KBgrimreaper
#54 interdiff-2889486-51-54.txt2.75 KBgrimreaper
#54 drupal-has_taxonomy_term_language-2889486-54.patch23.7 KBgrimreaper
#51 interdiff-2889486-48-51.txt3.2 KBgrimreaper
#51 drupal-has_taxonomy_term_language-2889486-51.patch21.22 KBgrimreaper
#49 drupal-has_taxonomy_term_language-2889486-48.patch23.29 KBgrimreaper
#41 interdiff.2889486.36-41.txt6.49 KBaleevas
#41 2889486-41.patch22.82 KBaleevas
#36 interdiff-2889486-35-36.txt915 bytesandersen_ti
#36 drupal-has_taxonomy_term_language-2889486-36.patch22.32 KBandersen_ti
#35 interdiff-2889486-32-35.txt2.87 KBgrimreaper
#35 drupal-has_taxonomy_term_language-2889486-35.patch23.56 KBgrimreaper
#32 interdiff-2889486-29-32.txt1020 bytesgrimreaper
#32 drupal-has_taxonomy_term_language-2889486-32.patch23.94 KBgrimreaper
#29 interdiff-2889486-28-29.txt5.34 KBgrimreaper
#29 drupal-has_taxonomy_term_language-2889486-29.patch23.89 KBgrimreaper
#28 interdiff-2889486-27-28.txt7.54 KBgrimreaper
#28 drupal-has_taxonomy_term_language-2889486-28.patch18.24 KBgrimreaper
#27 drupal-has_taxonomy_term_language-2889486-27.patch12.19 KBgrimreaper
#23 drupal-has_taxonomy_term_language-test_only-2889486-23.patch2.29 KBgrimreaper
#22 drupal-has_taxonomy_term_language-test_only-2889486-22.patch3.71 KBgrimreaper
#19 drupal-has_taxonomy_term_language-2889486-19.patch7.33 KBvacho
#10 drupal-has_taxonomy_term_language-2889486-10.patch6.92 KBmariiadeny
#10 interdiff-2889486-5-10-do-not-test.diff1.41 KBmariiadeny
#5 drupal-has_taxonomy_term_language-2889486-5.patch7.05 KBgrimreaper
#4 drupal-has_taxonomy_term_language-2889486-4.patch4.73 KBgrimreaper
#2 drupal-has_taxonomy_term_language-2889486-2.patch4.63 KBgrimreaper

Issue fork drupal-2889486

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:

Comments

Grimreaper created an issue. See original summary.

grimreaper’s picture

Assigned: grimreaper » Unassigned
Status: Active » Needs review
StatusFileSize
new4.63 KB

Here is the patch.

Status: Needs review » Needs work

The last submitted patch, 2: drupal-has_taxonomy_term_language-2889486-2.patch, failed testing. View results

grimreaper’s picture

Rework patch in case of the database column already exists.

grimreaper’s picture

StatusFileSize
new7.05 KB

It seems that the update of existing tables was not ok.

yogeshmpawar’s picture

Status: Needs work » Needs review

Triggering test bots.

Status: Needs review » Needs work

The last submitted patch, 5: drupal-has_taxonomy_term_language-2889486-5.patch, failed testing. View results

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.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.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should 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.

mariiadeny’s picture

mariiadeny’s picture

Status: Needs work » Needs review
andypost’s picture

Version: 8.5.x-dev » 8.6.x-dev
andypost’s picture

Schema & upgrade looks finished, now it needs tests to prove the bug category

borisson_’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Setting back to needs work based on #13.

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.

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.

belaz’s picture

Hi guys,

Test in wip,
Method to be added to core/modules/taxonomy/tests/src/Functional/TermLanguageTest.php


  /**
   * Tests that taxonomy terms are well managed with translatables nodes.
   */
  public function testTermTranslatedLinkedToNodes() {

    $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id(), $edit, t('Save'));
    $this->term = $this->createTerm($this->vocabulary, [
        'name' => 'Awesome node',
        'langcode' => 'bb',
    ]);

    // Create node.
    /** \Drupal\Core\Entity\EntityStorageInterface @var */
    $node_storage = \Drupal::entityTypeManager()->getStorage('node');

    /** \Drupal\node\NodeInterface @node */
    $node = $node_storage->create([
        'type' => 'article',
        'title' => 'Another node',
        'langcode' => 'bb',
        'field_tags' => [$this->term->id()],
    ]);
    $node->save();

    // TODO: use language manager to get the right language.
    $node->addTranslation('aa', [
        'title' => 'Node aa',
        'field_tags' => [],
    ]);
    $node->save();
    
    
    
    $url = $this->term->toUrl();
    $this->drupalGet($url);
    $this->assertSession()->responseContains('Awesome node');

    // TODO: See https://www.drupal.org/project/drupal/issues/2889486#comment-12142608 (scenario completion)


  }

In team with @qudec

andypost’s picture

Issue tags: +Needs reroll
vacho’s picture

Patch rerolled.

vacho’s picture

Issue tags: -Needs reroll

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.

grimreaper’s picture

Hello,

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.

grimreaper’s picture

Status: Needs work » Needs review
StatusFileSize
new2.29 KB

Ok,

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.

Status: Needs review » Needs work
lendude’s picture

  1. +++ b/core/modules/taxonomy/taxonomy.install
    @@ -248,3 +249,96 @@ function taxonomy_update_8702(&$sandbox) {
    +function taxonomy_update_8703() {
    

    this updates the schema, but do we also need an update for al existing references? or can they be just left blank?

  2. +++ b/core/modules/taxonomy/taxonomy.install
    @@ -248,3 +249,96 @@ function taxonomy_update_8702(&$sandbox) {
    +      'default' => $language,
    

    this seems wrong, it should just be an empty string

grimreaper’s picture

Assigned: Unassigned » grimreaper
Issue tags: +DrupalCon Amsterdam 2019

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

grimreaper’s picture

Assigned: grimreaper » Unassigned
StatusFileSize
new12.19 KB

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

grimreaper’s picture

Assigned: Unassigned » grimreaper
StatusFileSize
new18.24 KB
new7.54 KB

Almost done.

TODO: Tests for hook_update_N and tests for hook_post_update_NAME.

grimreaper’s picture

Status: Needs work » Needs review
StatusFileSize
new23.89 KB
new5.34 KB

Hello,

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.

Status: Needs review » Needs work

The last submitted patch, 29: drupal-has_taxonomy_term_language-2889486-29.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

rachel_norfolk’s picture

Issue tags: -DrupalCon Amsterdam 2019 +Amsterdam2019

retagging

grimreaper’s picture

Status: Needs work » Needs review
StatusFileSize
new23.94 KB
new1020 bytes

Update test are failing locally for me but at another place.

1) Drupal\Tests\system\Functional\Update\UpdatePathTestBaseFilledTest::testUpdatedSite
The link Continue was not found on the page.
Failed asserting that an array has the key 0.

/project/app/core/tests/Drupal/Tests/UiHelperTrait.php:495
/project/app/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php:314
/project/app/core/modules/system/tests/src/Functional/Update/UpdatePathTestBaseFilledTest.php:31

Let's see if testbot is happy with this change.

grimreaper’s picture

Assigned: grimreaper » Unassigned

Tests are green! \o/

lendude’s picture

Issue tags: -Needs tests +VDC

Really nice work!

  1. +++ b/core/modules/taxonomy/taxonomy.install
    @@ -248,3 +249,95 @@ function taxonomy_update_8702(&$sandbox) {
    +function taxonomy_update_8703() {
    

    Update number will need to be updated to _88*

  2. +++ b/core/modules/taxonomy/taxonomy.install
    @@ -248,3 +249,95 @@ function taxonomy_update_8702(&$sandbox) {
    +    Database::getConnection()->schema()->dropIndex('taxonomy_index', 'term_node');
    +    Database::getConnection()->schema()->addIndex(
    

    No need to drop it first, addIndex drops it if it exists

  3. +++ b/core/modules/taxonomy/taxonomy.install
    @@ -248,3 +249,95 @@ function taxonomy_update_8702(&$sandbox) {
    +  $manager = \Drupal::entityDefinitionUpdateManager();
    +  $entity_type = $manager->getEntityType('taxonomy_term');
    +  $manager->updateEntityType($entity_type);
    
    +++ b/core/modules/taxonomy/taxonomy.module
    @@ -541,11 +542,13 @@ function taxonomy_build_node_index($node) {
    -          ->fields(['sticky' => $sticky, 'created' => $node->getCreatedTime()])
    

    Is this needed? We aren't updating the entity are we?

  4. +++ b/core/modules/taxonomy/taxonomy.module
    @@ -580,6 +583,10 @@ function taxonomy_node_predelete(EntityInterface $node) {
    +    // Not necessary to add a condition on the langcode because when deleting
    +    // a translation, taxonomy_node_update() is called, so the entries for all
    +    // languages of the node will be deleted then reconstructed.
    +    // And when deleting the whole node, every entries should be removed.
    

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

  5. +++ b/core/modules/taxonomy/tests/src/Functional/TermIndexTest.php
    @@ -200,6 +201,92 @@ public function testTaxonomyIndex() {
    +    \Drupal::service('content_translation.manager')->setEnabled('node', 'article', TRUE);
    ...
    +    $node_storage = $this->container->get('entity_type.manager')->getStorage('node');
    

    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.

grimreaper’s picture

Thanks @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

andersen_ti’s picture

fix on batch for post_update: incorrect start range for the query.

Status: Needs review » Needs work

The last submitted patch, 36: drupal-has_taxonomy_term_language-2889486-36.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

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.

nikitagupta’s picture

Assigned: Unassigned » nikitagupta
nikitagupta’s picture

Assigned: nikitagupta » Unassigned
aleevas’s picture

Status: Needs work » Needs review
StatusFileSize
new22.82 KB
new6.49 KB

Trying to fix failed test

Status: Needs review » Needs work

The last submitted patch, 41: 2889486-41.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

kriboogh’s picture

#41 works (D8.9.1)

mayurjadhav’s picture

Assigned: Unassigned » mayurjadhav
mayurjadhav’s picture

Assigned: mayurjadhav » Unassigned
tanubansal’s picture

Issue is still there. Please update the patch for 9.1

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.

grimreaper’s picture

Assigned: Unassigned » grimreaper

Hello,

Trying to push it forward during DrupalCon Europe 2020.

First I will see if update is needed regarding Drupal 9.

grimreaper’s picture

Status: Needs work » Needs review
StatusFileSize
new23.29 KB

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

Status: Needs review » Needs work

The last submitted patch, 49: drupal-has_taxonomy_term_language-2889486-48.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

grimreaper’s picture

Status: Needs work » Needs review
StatusFileSize
new21.22 KB
new3.2 KB

Trying to make automated tests ok.

It seems that now, the index is already created and update test was referencing a file no more existing.

grimreaper’s picture

Issue tags: +Europe2020

Status: Needs review » Needs work

The last submitted patch, 51: drupal-has_taxonomy_term_language-2889486-51.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

grimreaper’s picture

Status: Needs work » Needs review
StatusFileSize
new23.7 KB
new2.75 KB

Status: Needs review » Needs work

The last submitted patch, 54: drupal-has_taxonomy_term_language-2889486-54.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

grimreaper’s picture

Status: Needs work » Needs review
StatusFileSize
new23.7 KB
new1.86 KB

It should be ok now.

And from the previous patch.

+++ b/core/modules/taxonomy/taxonomy.install
@@ -5,9 +5,110 @@
+  $definition_update_manager = \Drupal::entityDefinitionUpdateManager();
+  $entity_type = $definition_update_manager->getEntityType('taxonomy_term');
+  $definition_update_manager->updateEntityType($entity_type);

I don't know if it has a real effect but at least after that the update system is happy.

jungle’s picture

Status: Needs review » Needs work

Just a general review.

core/modules/taxonomy/taxonomy.module ✗ 1 more
line 14 Unused use statement
core/modules/taxonomy/tests/src/Functional/TermIndexTest.php ✗ 1 more
343 Tag value indented incorrectly; expected 1 space but found 2

2 CS violations have to be fixed.

+++ b/core/modules/taxonomy/tests/src/Functional/Update/TaxonomyIndexUpdateTest.php
@@ -0,0 +1,66 @@
+      __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.8.0.filled.standard.php.gz',
+      __DIR__ . '/../../../../../taxonomy/tests/fixtures/update/drupal-8.taxonomy-index-2889486.php',

Could use dirname(__DIR__, 5) . to replace __DIR__ . '/../../../../..;

grimreaper’s picture

Status: Needs work » Needs review
StatusFileSize
new23.49 KB
new1.79 KB

Hello,

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 if dirname(__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.

lendude’s picture

Status: Needs review » Needs work

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

+++ b/core/modules/taxonomy/taxonomy.post_update.php
@@ -18,3 +18,53 @@ function taxonomy_removed_post_updates() {
+  $query = $node_storage->getQuery()
+    ->accessCheck(FALSE)
+    ->sort('nid')
+    ->range($sandbox['current_node'], $sandbox['limit']);

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?

grimreaper’s picture

Hello,

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.

grimreaper’s picture

Status: Needs work » Needs review
StatusFileSize
new23.67 KB
new1.61 KB

New patch and interdiff to take comment 59 review into account.

catch’s picture

Status: Needs review » Needs work
+++ b/core/modules/taxonomy/taxonomy.post_update.php
@@ -44,12 +46,13 @@ function taxonomy_post_update_populate_taxonomy_index_langcode(&$sandbox = NULL)
-
+  $entity_ids = $database->select('taxonomy_index')
+    ->fields('taxonomy_index', ['nid'])
+    ->condition('nid', $sandbox['current_node'], '>')
+    ->distinct()
+    ->range(NULL, $sandbox['limit'])
+    ->execute()
+    ->fetchCol();

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

grimreaper’s picture

Status: Needs work » Needs review
StatusFileSize
new23.76 KB
new1.53 KB

Thanks @catch for the review.

Here is the new patch fixing the points.

grimreaper’s picture

Assigned: grimreaper » Unassigned
abhijith s’s picture

StatusFileSize
new45.52 KB

Applied patch #63 and its not working.The non referenced translated nodes are still showing in the list.

after

grimreaper’s picture

What 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"?

sokru’s picture

Status: Needs review » Needs work
Issue tags: +Needs change record
StatusFileSize
new94.64 KB

Added "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.
Screenshot of views UI
- If importing manually patched views.view.taxonomy_term.yml file the filter works fine. But if one deletes it, its not possible to add it back.

grimreaper’s picture

Assigned: Unassigned » grimreaper
Issue tags: +GlobalContributionWeekend2021

Working on it.

grimreaper’s picture

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

grimreaper’s picture

Status: Needs work » Needs review
grimreaper’s picture

Assigned: grimreaper » Unassigned
Issue tags: -Needs change record

Change record created https://www.drupal.org/node/3195569.

Needs review.

ericdsd’s picture

Status: Needs review » Reviewed & tested by the community
sokru’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new158.49 KB

I 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/export
8. 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:
Screenshot of views UI
vs.
One in #69:

It's missing "Content language selected for page" option.

Edit: Copy-paste error on 8.

grimreaper’s picture

Assigned: Unassigned » grimreaper

Ok, I understand now comment 67.

Checking.

grimreaper’s picture

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

grimreaper’s picture

Assigned: grimreaper » Unassigned
Status: Needs work » Needs review

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

rachel_norfolk’s picture

Issue tags: -GlobalContributionWeekend2021 +ContributionWeekend2021

Just doing a little tag tidying. Nice work everyone!!

liber_t’s picture

Status: Needs review » Reviewed & tested by the community
catch’s picture

Status: Reviewed & tested by the community » Needs work

Found a couple of issues, overall looks pretty good although I need to review the logic and update a bit more

  1. +++ b/core/modules/taxonomy/src/TermStorageSchema.php
    @@ -60,10 +60,17 @@ protected function getEntitySchema(ContentEntityTypeInterface $entity_type, $res
             ],
    +        'langcode' => [
    +          'description' => 'The langcode of the node.',
    +          'type' => 'varchar_ascii',
    +          'length' => 12,
    +          'not null' => TRUE,
    +          'default' => '',
    +        ],
    

    Is this the node langcode or the translation langcode, or both?

  2. +++ b/core/modules/taxonomy/src/TermStorageSchema.php
    @@ -60,10 +60,17 @@ protected function getEntitySchema(ContentEntityTypeInterface $entity_type, $res
    -      'primary key' => ['nid', 'tid'],
    +      'primary key' => ['nid', 'tid', 'langcode'],
           'indexes' => [
    -        'term_node' => ['tid', 'status', 'sticky', 'created'],
    +        'term_node' => ['tid', 'status', 'sticky', 'created', 'langcode'],
           ],
           'foreign keys' => [
    

    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.

  3. +++ b/core/modules/taxonomy/taxonomy.install
    @@ -5,9 +5,110 @@
    +          'default' => 0,
    +        ],
    +        'status' => [
    +          'description' => 'Boolean indicating whether the node is published (visible to nonadministrators).',
    +          'type' => 'int',
    +          'not null' => TRUE,
    

    non-administrators

  4. +++ b/core/modules/taxonomy/tests/src/Functional/TermIndexTest.php
    @@ -230,6 +231,92 @@ public function testTaxonomyIndex() {
    +      'fr' => 0,
    +    ]);
    +
    +    // Add a reference to the term in fr.
    +    $node = $node_storage->load($nid);
    

    We should refer to the languages by name rather than langcode in the comments I think.

  5. +++ b/core/modules/taxonomy/tests/src/Functional/TermIndexTest.php
    @@ -230,6 +231,92 @@ public function testTaxonomyIndex() {
    +
    +    // Delete ur translation.
    +    $node = $node_storage->load($nid);
    +    $node->removeTranslation('ur');
    +    $node->save();
    

    Same here.

  1. +++ b/core/modules/taxonomy/tests/src/Functional/Views/TaxonomyTermViewTest.php
    @@ -115,15 +115,34 @@ public function testTaxonomyTermView() {
     
    +    // Create a second term that will not reference the term in one of its
    +    // language.
    +    $edit = [];
    

    'one of its languages'

  2. +++ b/core/modules/taxonomy/tests/src/Functional/Views/TaxonomyTermViewTest.php
    @@ -115,15 +115,34 @@ public function testTaxonomyTermView() {
         $this->assertNoText($original_title);
         $this->assertText($translated_title);
    +    // As node 2 do not reference the term, it should not appear on the
    +    // translated term page.
    

    Should be 'does not reference'

dww’s picture

Status: Needs work » Needs review
StatusFileSize
new22.62 KB
new3.41 KB

This 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

dww’s picture

Issue tags: +Bug Smash Initiative
grimreaper’s picture

Hello,

For point 1:

+++ b/core/modules/taxonomy/taxonomy.module
@@ -336,7 +336,7 @@ function taxonomy_build_node_index($node) {
         foreach ($node->getTranslationLanguages() as $language) {

Langcode of the node and the translations.

Thanks @dww for fixing the other points.

dww’s picture

StatusFileSize
new22.64 KB
new523 bytes

@Grimreaper: Thanks for clarifying. Updating the DB schema definition comment accordingly. Hope this is agreeable.

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.

kriboogh’s picture

StatusFileSize
new12.32 KB

Patch #83 doesn't apply to 9.2.0, so I re-roll against 9.2.0 tag.

mschudders’s picture

StatusFileSize
new22.92 KB

Reroll for 9.2.0 working patch.

Status: Needs review » Needs work

The last submitted patch, 86: 2889486-86.patch, failed testing. View results

dubey.surbhit’s picture

Status: Needs work » Needs review
StatusFileSize
new23.31 KB

Reroll patch for 9.3.x and Fixed the fails of #86

dubey.surbhit’s picture

StatusFileSize
new23.31 KB
new302 bytes

Fixed the custom command fails

dubey.surbhit’s picture

StatusFileSize
new22.96 KB

Fixed the custom command fail error.

dubey.surbhit’s picture

StatusFileSize
new949 bytes

Added interdiff

mschudders’s picture

StatusFileSize
new22.89 KB

reroll for 9.3.x

mschudders’s picture

StatusFileSize
new22.86 KB

reroll for 9.2.5 (I hope)

mschudders’s picture

StatusFileSize
new22.86 KB

test against latest 9.2.x

works on 9.2.5

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.

mschudders’s picture

StatusFileSize
new0 bytes

reroll for 9.3.0

mschudders’s picture

StatusFileSize
new22.9 KB

patch was empty for some reason

Status: Needs review » Needs work

The last submitted patch, 97: 2889486_95.patch, failed testing. View results

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.

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.

vsujeetkumar’s picture

Status: Needs work » Needs review
StatusFileSize
new22.91 KB
new1.03 KB

Reroll patch created for 9.5.x, Please have a look.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new86 bytes

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

ameymudras’s picture

Status: Needs work » Needs review
StatusFileSize
new22.75 KB

Rerolling for 10.x, couldn't generate an inderdiff

borisson_’s picture

Status: Needs review » Needs work

Both phpstan and phpcs are unhappy about the latest patch.

anchal_gupta’s picture

StatusFileSize
new22.86 KB
new518 bytes

Fixed CCF.

anchal_gupta’s picture

Status: Needs work » Needs review
borisson_’s picture

Status: Needs review » Needs work

#105 Fixed CCF.

Well no, it still fails.
Please run the script locally before using the drupal.org resources.

core/scripts/dev/commit-code-check.sh --drupalci

_pratik_’s picture

Status: Needs work » Needs review
StatusFileSize
new30.72 KB
new10.38 KB
tanuj.’s picture

Status: Needs review » Needs work
StatusFileSize
new24.7 KB
new2.71 KB

Adding a reroll patch for 10.1.x and fixing all CCF issues and some other phpcs issues.

tanuj.’s picture

Status: Needs work » Needs review
_pratik_’s picture

StatusFileSize
new31.18 KB
smustgrave’s picture

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

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

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.

leo liao’s picture

StatusFileSize
new30.57 KB

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

leo liao’s picture

StatusFileSize
new30.59 KB

fixed test.

leo liao’s picture

StatusFileSize
new24.15 KB

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

leo liao’s picture

StatusFileSize
new24.4 KB

Infinite loop updb.

gauravvvv’s picture

StatusFileSize
new24.4 KB
new1.16 KB

Fixed CCF failure, added interdiff for same

impol’s picture

StatusFileSize
new19.16 KB

Re-rolled patch from #118 for 10.2.x

sourabhjain’s picture

StatusFileSize
new20.09 KB
new2.49 KB

Fixed CCF failure in #119, added interdiff for same

sumit saini’s picture

StatusFileSize
new20.26 KB
new1.89 KB

Patch in #120 is missing a use statement for Node class.
Updated patch in #120 to fix it. (created for 10.2.x)

sakthi_dev made their first commit to this issue’s fork.

kriboogh’s picture

Status: Needs work » Needs review
StatusFileSize
new20.49 KB
new12.84 KB

Add patch for MR!7968.
Fixed phpcs and tests.

kriboogh’s picture

Status: Needs review » Needs work
StatusFileSize
new20.85 KB

Added MR for roll-back to 10.3 and patch.

kriboogh’s picture

Status: Needs work » Needs review
StatusFileSize
new1.76 KB
new20.71 KB

Fixed mysql issue with primary key creation on 10.3

smustgrave’s picture

Status: Needs review » Needs work

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

kriboogh’s picture

Status: Needs work » Needs review

MR!9023 is for 10.3 (patch 127)

MR!7968 is for 11 (patch 124)

smustgrave’s picture

Status: Needs review » Needs work

Left some comments on MR.

shalini_jha made their first commit to this issue’s fork.

shalini_jha’s picture

Status: Needs work » Needs review

I have updated the code based on PR feedback and fixed the pipeline for the failing test. moving this to NR.
Kindly review.

sagarmohite0031’s picture

Hello,
MR applied successfully, Both articles are displayed in both languages.
Also can add filter.
Check attachments-

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new90 bytes

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

shalini_jha’s picture

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

Status: Needs review » Needs work
StatusFileSize
new90 bytes

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

shalini_jha’s picture

Assigned: Unassigned » shalini_jha

shalini_jha changed the visibility of the branch 2889486-has-taxonomy-term-10.3 to hidden.

shalini_jha’s picture

Assigned: shalini_jha » Unassigned
Status: Needs work » Needs review

Rebased & fixed conflicts . Moving back to review.

asawari’s picture

StatusFileSize
new29.46 KB
new33.68 KB
new33.2 KB

Hi,
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

jan kellermann made their first commit to this issue’s fork.

smustgrave’s picture

Status: Needs review » Needs work

Left comments on MR, thanks for keeping it going!

shalini_jha’s picture

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

evilargest’s picture

StatusFileSize
new19.88 KB

Created a patch from the latest changes; works fine on 11.2.4

mparker17 made their first commit to this issue’s fork.

mparker17’s picture

StatusFileSize
new20.26 KB

I needed this patch for a Drupal 10.4 site, so I created branch 2889486-has-taxonomy-term-10.4 in the issue fork (but haven't created a merge request).

Attaching a patch of the changes. I just rebased so there is no interdiff.

swilmes’s picture

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

evilargest’s picture

StatusFileSize
new19.45 KB

Reroll of #144 for 11.3.1

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.