Views contextual filter replacement pattern doesn't use referenced entity's title available

Created on 10 January 2020, almost 5 years ago
Updated 9 September 2024, 2 months ago

I'm not sure what the root cause of this bug is, but I figured I'd start here.

I have a View set up with the path

node/%/events

that lists all content of type Event which is attached to an organic group. This works great, and using Subpathauto I can access the pages via the OG node's alias, e.g.

/mygroup/events

. Beautiful.

The problem is that I want the title of the base node to be shown in the page title and it's only showing the node's ID. Normally I would be able to do this using the "Override title" option on the contextual filter and fill in something like Upcoming Events for {{ arguments.og_audience_target_id }}, because the replacement patterns specifically says:

The following replacement tokens are available for this argument.

{{ arguments.og_audience_target_id }} == Content: Organization (og_audience) title
{{ raw_arguments.og_audience_target_id }} == Content: Organization (og_audience) input

In theory the {{ arguments.og_audience_target_id }} string should output the node's title, but instead it's outputting the raw input.

There's an existing core issue focused on this problem ( 🐛 views - contextual filter - how to get term name, not term id Closed: duplicate ) but there isn't a workable solution that directly affects the contextual filters.

I'm starting here on the off chance that Sub-pathauto is changing Views' behavior, if the problem ends up being elsewhere I'll move the issue.

🐛 Bug report
Status

Postponed

Version

1.0

Component

Code

Created by

🇺🇸United States DamienMcKenna NH, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇨🇦Canada nickdickinsonwilde Victoria, BC (T'So-uke lands)

    This module doesn't *directly* impact the view. But it doesn't surprise me that it messes that up. I think it should be possible to fix generically, but might be hard. Putting as postponed since definitely not on my to do list right now but seems like a valid bug as well.
    Thanks for the workaround too

  • 🇦🇺Australia Katy Swain

    This appears to be a D8+ Views regression. 🐛 Fix label token replacement for views entity reference arguments Fixed I've been wrestling with it for ages, and have only installed subpathauto five minutes ago, so it's definitely not this module's fault.

    I'm just getting back into Drupal after nearly a decade, and this used to be a standard content modelling trope with me; an entity overview page with a whole bunch of child pages following relationships to other entities. I can't imagine how hordes of people aren't screaming over this when something as elementary as 'taxonomy/term/1/articles' can only be re-titled 'Articles About 1' rather than 'Articles About My Cat Desmond'.

  • 🇺🇸United States joshuami Portland, OR

    I figured out a way to address this without any custom code, but it does require Twig Tweak and Metatag .

    I appreciated the approach that @DamienMcKenna provided in comment #2, but it only addresses the title provided by the page_title.html.twig template and not the <title> element. I was able to get the text for the title of the contextual argument by passing it into Twig Tweaks drupal_field() function: {{ drupal_field('title', 'node', arguments.id) }} News.

    This works for any entity type that has fields and where you can only get the ID from the contextual argument and not the title/name/label output—such as when you have a Search API Solr view that you are passing a contextual argument ID for an entity referenced field such as "parent group" or "tag".

    I hope this helps anyone that might be tripped up on this issue and is looking for a way to set both the view title override and the metatag title element override.

  • 🇺🇸United States joshuami Portland, OR

    I should add that this is not a subpathauto issue and Fix label token replacement for views entity reference arguments 🐛 Fix label token replacement for views entity reference arguments Fixed fixes the issue for Taxonomy Terms and entity types—I would this it would fix the OG argument example that opened this issue. Search API views with a contextual argument are still not converted correctly. I wonder if we should open a separate issue in that queue and close this.

    It feels kinda like https://git.drupalcode.org/project/search_api/-/blob/8.x-1.x/src/Plugin/... should be rewritten as SearchAPIEntity.php—as it appears you can pass a taxonomy term and get the correct label, but not any other entity type. 🤔

Production build 0.71.5 2024