Allow use of node route parameter for use in views contextual filter

Created on 21 August 2025, about 1 month ago

Problem/Motivation

I have a node page that includes views in the twig template that are printed using twig_tweak. Ex:

{{ drupal_block('views_block:my_custom_view-block_1') }}

These views use a contextual filter "Content ID" (nid), which is configured to use a default argument "Content ID from URL". This works fine when viewing the node page, but when I view the entity print url, "print/pdf/node/123/debug", the default argument does not work.

Proposed resolution

Drupal normally uses route parameters to get the current node. The views code in question uses:

 // \Drupal\node\Plugin\views\argument_default\Node::getArgument
 $node = $this->routeMatch->getParameter('node')

The entity print routing includes parameters "entity_type" and "entity_id", but not node. One way to get node is to decorate the current_route_match service so that the node parameter can be added to the available parameters.

The attached patch is a first attempt at this, which adds support for "node". This could be extended to also include other entity types, but this solves my use case for now.

✨ Feature request
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States jessehs Taos, New Mexico

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

Comments & Activities

Production build 0.71.5 2024