The taxonomy module's Taxonomy Term Name validator for views contextual filters (located here: core/modules/taxonomy/src/Plugin/views/argument_validator/TermName.php) does not work with translations.

From TermName.php:

  public function validateArgument($argument) {
    if ($this->options['transform']) {
      $argument = str_replace('-', ' ', $argument);
      $this->argument->argument = $argument;
    }
    $terms = $this->termStorage->loadByProperties(['name' => $argument]);

The problem is present whether or not the transform option is selected, it seems that loading by name is where this fails.

Steps to Reproduce:

  1. Enable translation and translate one content type with a term reference field; also translate the vocabulary
  2. Build a view of that content type and add a relationship to the term referenced by the term reference field; the view should have a filter for translation language
  3. Add a "Name" contextual filter, using the relationship
  4. Select the Taxonomy Term Name validator
  5. In the preview, attempt to filter by the translated term name

I have described this issue in more detail here: https://drupal.stackexchange.com/questions/271754/multiple-relations-and...

CommentFileSizeAuthor
#8 view_filtered_by_term_name.yml25.27 KBjmee
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

andileco created an issue. See original summary.

hansfn’s picture

Just some specific info about the bug: The validator calls:

$terms = $this->termStorage->loadByProperties(['name' => $argument]);

The term storage is a normal entity storage. If you look at the term name entity you'll notice that the name property has one key for each translation, but these aren't used when loading - only the "x-default" key AFAICT. Hence the validator finds no terms for a any translated term names.

Version: 8.6.2 » 8.6.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.

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

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Branches prior to 8.8.x are not supported, and Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

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

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

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

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should 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.

jmee’s picture

Title: The Term Name Argument Validator Does Not Work with Translations » The Term Name Argument Validator for Views Contextual Fitlers Does Not Work with Translations
Issue summary: View changes
Related issues: +#2179909: Translation failing, localised term contextual filter with validation and transform spaces to dash, +#2313159: [meta] Make multilingual views work, +#3064479: Return translated term name on taxonomy term views argument
FileSize
25.27 KB

I just ran into this issue, spent some time looking into it and came to the same conclusion as @hansfn

Also an issue in D7: 2179909 - Translation failing, localised term contextual filter with validation and transform spaces to dash

I started creating a new ticket, so I'll add the information I had typed up here, maybe it will help this issue get some love

Some more details about this issue:

The views Contextual filter does not use the localized term name when using validation criteria other than "Basic validation".

In my case, the path alias matches a term name and this is used as the contextual filter. Term names and path aliases are translated.

If no validation criteria is specified or "Basic validation" is selected, the view works as expected, and using translated term names as the contextual filter returns content related to the term.

However, when the validator is "Taxonomy term", the localised term names no longer return results (no query is run).

This validator is particularly helpful, since it allows us to transform the term name for use as a filter ("transform dashes in URL to space in term name filter values").

My use case:

I've attached the config for my view ( view_filtered_by_term_name.yml ), but here's a description of what I did:

  1. Create a vocabulary and enable translation, add terms and translate of term names
  2. Create a content type and enable translation, making sure to enable translation of path alias field
  3. Add content where node title and path alias match a term name added in previous step, and translate the content (including path alias)
  4. Create a view displaying content from the previously created translatable node type
  5. Add a relationship to Taxonomy terms on node and filter by vocabulary
  6. Add a Taxonomy Term: Name contextual filter with relationship to the term added in the previous step. Configure contextual filter as:
    1. When filter value is NOT available = Provide default URL
    2. Type: Raw value from URL
    3. Use path alias = true
    4. Specify validation criteria: Taxonomy term, select vocabulary, and enable "Transform dashes in URL to spaces in term name filter values"
  7. Save view and place as block / use views preview to test query based on given term name
  8. Result is that the view will display content when the term name is passed as contextual filter in the site's default language, but no query runs when localised term name is passed as contextual filter.
jmee’s picture

Title: The Term Name Argument Validator for Views Contextual Fitlers Does Not Work with Translations » The Term Name Argument Validator for Views Contextual Filters Does Not Work with Translations

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

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should 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.

ThuleNB’s picture

I am facing the same issue.
Does somebody figure out a workaround for this?

Version: 9.5.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. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.