STEPS TO REPRODUCE

  • Enable 2 languages
  • Create a new content type: news
  • Enable it for translation
  • Create a new vocabulary: categories
  • Enable it for translation
  • Create a taxonomy reference on content type news which is language neutral
  • Create a View (it should show for current language on the page) and create a filter on the categories term
  • Create the node in primary language
  • Translate the node to the secondary language
  • Try filter the node with the term filter on secondary language, and it won't display

I have a content type News.
I have a vocabulary Categories.

The Categories are translatable.
The News are translatable.

The taxonomy reference on News are language neutral and should be shared on the news translations.

Drupal version: 8.2.1
PHP version: 5.5.9
Web server: Apache
OS: Ubuntu 14.04

On the taxonomy term field, the langcode is stored on the node first created. So If I create an english node first, it's "en" and If I create a French one, it's fr.

This is a problem, because now I cannot filter on the categories on the translated language: The SQL produced by looks like:

SELECT node_field_data.created AS node_field_data_created, node_field_data.nid AS nid
FROM 
{node_field_data} node_field_data
INNER JOIN {node__field_news_main_categories} node__field_news_main_categories ON node_field_data.nid = node__field_news_main_categories.entity_id AND (node__field_news_main_categories.deleted = '0' AND node__field_news_main_categories.langcode = node_field_data.langcode)
WHERE (( (node__field_news_main_categories.field_news_main_categories_target_id = '89') )AND(( (node_field_data.status = '1') AND (node_field_data.type IN  ('news')) AND (node_field_data.langcode IN  ('fr')) )))
ORDER BY node_field_data_created DESC
LIMIT 10 OFFSET 0

Since the taxonomy term is LANGUAGE NEUTRAL on the node, shouldn't it store the reference with langcode und?

The easiset solution, I guess would be to determine if the field is language neutral and if so remove this part:

AND node__field_news_main_categories.langcode = node_field_data.langcode

Here's the view:

uuid: 1d45dfb3-edbd-493d-bcaf-dec0e12931c0
langcode: en
status: true
dependencies:
  config:
    - core.entity_view_mode.node.teaser
    - node.type.news
    - taxonomy.vocabulary.content_categories_main
  module:
    - node
    - search
    - taxonomy
    - user
id: news_article_list
label: 'News/article list'
module: views
description: ''
tag: ''
base_table: node_field_data
base_field: nid
core: 8.x
display:
  default:
    display_plugin: default
    id: default
    display_title: Master
    position: 0
    display_options:
      access:
        type: perm
        options:
          perm: 'access content'
      cache:
        type: tag
        options: {  }
      query:
        type: views_query
        options:
          disable_sql_rewrite: false
          distinct: false
          replica: false
          query_comment: ''
          query_tags: {  }
      exposed_form:
        type: basic
        options:
          submit_button: Apply
          reset_button: false
          reset_button_label: Reset
          exposed_sorts_label: 'Sort by'
          expose_sort_order: true
          sort_asc_label: Asc
          sort_desc_label: Desc
      pager:
        type: full
        options:
          items_per_page: 10
          offset: 0
          id: 0
          total_pages: null
          tags:
            previous: ''
            next: ''
            first: ''
            last: ''
          expose:
            items_per_page: false
            items_per_page_label: 'Items per page'
            items_per_page_options: '5, 10, 25, 50'
            items_per_page_options_all: false
            items_per_page_options_all_label: '- All -'
            offset: false
            offset_label: Offset
          quantity: 9
      style:
        type: default
        options:
          grouping: {  }
          row_class: ''
          default_row_class: true
          uses_fields: false
      row:
        type: 'entity:node'
        options:
          relationship: none
          view_mode: teaser
      fields:
        title:
          id: title
          table: node_field_data
          field: title
          entity_type: node
          entity_field: title
          label: ''
          alter:
            alter_text: false
            make_link: false
            absolute: false
            trim: false
            word_boundary: false
            ellipsis: false
            strip_tags: false
            html: false
          hide_empty: false
          empty_zero: false
          settings:
            link_to_entity: true
          plugin_id: field
          relationship: none
          group_type: group
          admin_label: ''
          exclude: false
          element_type: ''
          element_class: ''
          element_label_type: ''
          element_label_class: ''
          element_label_colon: true
          element_wrapper_type: ''
          element_wrapper_class: ''
          element_default_classes: true
          empty: ''
          hide_alter_empty: true
          click_sort_column: value
          type: string
          group_column: value
          group_columns: {  }
          group_rows: true
          delta_limit: 0
          delta_offset: 0
          delta_reversed: false
          delta_first_last: false
          multi_type: separator
          separator: ', '
          field_api_classes: false
      filters:
        status:
          value: '1'
          table: node_field_data
          field: status
          plugin_id: boolean
          entity_type: node
          entity_field: status
          id: status
          expose:
            operator: ''
          group: 1
        type:
          id: type
          table: node_field_data
          field: type
          value:
            news: news
          entity_type: node
          entity_field: type
          plugin_id: bundle
        created:
          id: created
          table: node_field_data
          field: created
          relationship: none
          group_type: group
          admin_label: ''
          operator: '>='
          value:
            min: ''
            max: ''
            value: ''
            type: date
          group: 1
          exposed: true
          expose:
            operator_id: created_op
            label: 'Authored on'
            description: ''
            use_operator: false
            operator: created_op
            identifier: custom_date_filter_down
            required: false
            remember: false
            multiple: false
            remember_roles:
              authenticated: authenticated
              anonymous: '0'
              administrator: '0'
              editor: '0'
              webmaster: '0'
          is_grouped: false
          group_info:
            label: ''
            description: ''
            identifier: ''
            optional: true
            widget: select
            multiple: false
            remember: false
            default_group: All
            default_group_multiple: {  }
            group_items: {  }
          entity_type: node
          entity_field: created
          plugin_id: date
        field_news_main_categories_target_id:
          id: field_news_main_categories_target_id
          table: node__field_news_main_categories
          field: field_news_main_categories_target_id
          relationship: none
          group_type: group
          admin_label: ''
          operator: or
          value: {  }
          group: 1
          exposed: true
          expose:
            operator_id: field_news_main_categories_target_id_op
            label: 'Main category'
            description: ''
            use_operator: false
            operator: field_news_main_categories_target_id_op
            identifier: main_category
            required: false
            remember: false
            multiple: false
            remember_roles:
              authenticated: authenticated
              anonymous: '0'
              administrator: '0'
              editor: '0'
              webmaster: '0'
            reduce: false
          is_grouped: false
          group_info:
            label: ''
            description: ''
            identifier: ''
            optional: true
            widget: select
            multiple: false
            remember: false
            default_group: All
            default_group_multiple: {  }
            group_items: {  }
          reduce_duplicates: false
          type: select
          limit: true
          vid: content_categories_main
          hierarchy: false
          error_message: true
          plugin_id: taxonomy_index_tid
        keys:
          id: keys
          table: node_search_index
          field: keys
          relationship: none
          group_type: group
          admin_label: ''
          operator: optional
          value: ''
          group: 1
          exposed: true
          expose:
            operator_id: keys_op
            label: Search
            description: ''
            use_operator: false
            operator: keys_op
            identifier: search
            required: false
            remember: false
            multiple: false
            remember_roles:
              authenticated: authenticated
              anonymous: '0'
              administrator: '0'
              editor: '0'
              webmaster: '0'
          is_grouped: false
          group_info:
            label: ''
            description: ''
            identifier: ''
            optional: true
            widget: select
            multiple: false
            remember: false
            default_group: All
            default_group_multiple: {  }
            group_items: {  }
          plugin_id: search_keywords
      sorts:
        created:
          id: created
          table: node_field_data
          field: created
          relationship: none
          group_type: group
          admin_label: ''
          order: DESC
          exposed: false
          expose:
            label: ''
          granularity: second
          entity_type: node
          entity_field: created
          plugin_id: date
      header: {  }
      footer: {  }
      empty: {  }
      relationships: {  }
      arguments: {  }
      display_extenders: {  }
      css_class: 'date-filter-workaround-form'
      rendering_language: '***LANGUAGE_language_interface***'
    cache_metadata:
      max-age: -1
      contexts:
        - 'languages:language_interface'
        - url
        - url.query_args
        - user
        - 'user.node_grants:view'
        - user.permissions
      tags: {  }
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

johndevman created an issue. See original summary.

johnwebdev’s picture

Issue summary: View changes
johnwebdev’s picture

Component: locale.module » views.module
johnwebdev’s picture

Issue summary: View changes
johnwebdev’s picture

So I've tracked the issue down to views.view.inc on views_field_default_views_data()

  // Build the relationships between the field table and the entity tables.
  $table_alias = $field_tables[EntityStorageInterface::FIELD_LOAD_CURRENT]['alias'];
  if ($data_table) {
    // Tell Views how to join to the base table, via the data table.
    $data[$table_alias]['table']['join'][$data_table] = array(
      'table' => $table_mapping->getDedicatedDataTableName($field_storage),
      'left_field' => $entity_type->getKey('id'),
      'field' => 'entity_id',
      'extra' => array(
        array('field' => 'deleted', 'value' => 0, 'numeric' => TRUE),
        array('left_field' => 'langcode', 'field' => 'langcode'),
      ),
    );
  }

And the issue can be solved by removing: array('left_field' => 'langcode', 'field' => 'langcode'),. However, we should probably determine if the field is translatable, and conditionally add it.

johnwebdev’s picture

That seemed to work as expected. Here's a Terminal diff just to show what I did, I'll let some people put in some thoughts before I actually submit it:

diff --git a/core/modules/views/views.views.inc b/core/modules/views/views.views.inc
index 93a659c..6aee14e 100644
--- a/core/modules/views/views.views.inc
+++ b/core/modules/views/views.views.inc
@@ -352,6 +352,13 @@ function views_field_default_views_data(FieldStorageConfigInterface $field_stora
     );
   }

+  $extra_data = array();
+  $extra_data[] = array('field' => 'deleted', 'value' => 0, 'numeric' => TRUE);
+
+  if ($field_storage->isTranslatable() === TRUE) {
+    $extra_data[] = array('left_field' => 'langcode', 'field' => 'langcode');
+  }
+
   // Build the relationships between the field table and the entity tables.
   $table_alias = $field_tables[EntityStorageInterface::FIELD_LOAD_CURRENT]['alias'];
   if ($data_table) {
@@ -360,10 +367,7 @@ function views_field_default_views_data(FieldStorageConfigInterface $field_stora
       'table' => $table_mapping->getDedicatedDataTableName($field_storage),
       'left_field' => $entity_type->getKey('id'),
       'field' => 'entity_id',
-      'extra' => array(
-        array('field' => 'deleted', 'value' => 0, 'numeric' => TRUE),
-        array('left_field' => 'langcode', 'field' => 'langcode'),
-      ),
+      'extra' => $extra_data,
     );
   }
   else {
cilefen’s picture

Priority: Critical » Major

Hi @johndevman:

This is a detailed error report. But, it does not meet the criteria for being a critical issue.

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

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

shaal’s picture

Issue tags: +Baltimore2017

working on triaging this issue in Drupalcon Baltimore 2017 sprint

shaal’s picture

Version: 8.3.x-dev » 8.4.x-dev
Issue tags: +needs patch

I was able to reproduce this issue on 8.4.x

Cannot test the fix submitted by #6 because it's just a text comment and not a patch file.

dzinkevich’s picture

Here's a proper patch for #6.

I have not tested it for accuracy.

The code looks like it will do the right thing. I think there should be a better name for the $extra_data variable.

dzinkevich’s picture

Status: Active » Needs review
shaal’s picture

Issue tags: +Triaged for D8 major current state
johnwebdev’s picture

I agree dzinkevich, we should just be able to call it $extra, I suppose? We could also omit the === TRUE part, since the method does always return a boolean, and using is in the prefix indicates that is an boolean as well.

Thanks for attaching it as a proper patch.

Status: Needs review » Needs work
cilefen’s picture

@shaal I am going over the issues analyzed at the Baltimore triage in order to assign credit. I would like to give you credit for the work done, but I can't tell whether or not all steps of the triage were completed by reading the comments. We like to see documented steps (even if brief). Here are some made-up examples of documented triage steps:

  • I tested the steps to reproduce and they did (or did not) work (so I am tagging it "Needs issue summary update").
  • I searched for duplicate issues but could not find any.
  • I checked the issue summary and it is accurate and up-to-date.
  • Etc...
shaal’s picture

I was able to reproduce the bug on Drupal 8.4.x clean installation.
I followed the steps that were already described beforehand -

  1. Enable 2 languages
  2. Create a new content type: news
  3. Enable it for translation
  4. Create a new vocabulary: categories
  5. Enable it for translation
  6. Create a taxonomy reference on content type news which is language neutral
  7. Create a View (it should show for current language on the page) and create a filter on the categories term
  8. Create the node in primary language
  9. Translate the node to the secondary language
  10. Try filter the node with the term filter on secondary language, and it won't display

I checked the issue summary and it is accurate and up-to-date.
I couldn't any similar/duplicate issues.
I could not apply the patch submitted by @dzinkevich

yogeshmpawar’s picture

Status: Needs work » Needs review
FileSize
1.2 KB

Re-roll the #11 patch because it's failed to apply on 8.4.x branch.

cilefen’s picture

I am updating credit - thank you @shaal!

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

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now 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.

ollu’s picture

Today I updated from 8.3.7 to 8.4 and since we had the issue before I tried applying the patch but did not succeed. When I followed the instructions on how to reproduce the problem all went well for me and the translated node appeared on the page as expected.

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.

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.

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.

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.

quietone’s picture

Status: Needs review » Closed (cannot reproduce)
Issue tags: -needs patch, -Triaged for D8 major current state +riaged for D8 major current state

I tested this on 9.4.x and was not able to reproduce this error. I followed the steps given in the Issue Summary. This was also reported as not not reproducible on Drupal 8.4. in #21.

Therefore, closing as cannot reproduce. If you are experiencing this problem on a supported version of Drupal reopen the issue, by setting the status to 'Active', and provide complete steps to reproduce the issue (starting from "Install Drupal core").

Thanks!

quietone’s picture

Issue tags: +Bug Smash Initiative

Adding tag.