Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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:
- Enable translation and translate one content type with a term reference field; also translate the vocabulary
- 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
- Add a "Name" contextual filter, using the relationship
- Select the Taxonomy Term Name validator
- 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...
Comment | File | Size | Author |
---|---|---|---|
#8 | view_filtered_by_term_name.yml | 25.27 KB | jmee |
Comments
Comment #2
hansfn CreditAttribution: hansfn as a volunteer commentedJust some specific info about the bug: The validator calls:
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.
Comment #8
jmee CreditAttribution: jmee commentedI 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:
Comment #9
jmee CreditAttribution: jmee commentedComment #11
ThuleNB CreditAttribution: ThuleNB commentedI am facing the same issue.
Does somebody figure out a workaround for this?