The node views argument default expects node parameter, node_preview provided when previewing nodes

Created on 5 February 2018, over 6 years ago
Updated 3 February 2023, over 1 year ago

Problem/Motivation

When previewing nodes that use a Views Reference Field β†’ with a view that includes a node contextual filter configured to use the default argument using the content id from the URL, the view does not render any results as expected and seen when rendering the node.

The node views argument default expects the node parameter, as seen here.

\Drupal\node\Plugin\views\argument_default\Node::getArgument()

  public function getArgument() {
    if (($node = $this->routeMatch->getParameter('node')) && $node instanceof NodeInterface) {
      return $node->id();
    }
  }

However, the entity.node.preview route provides the node_preview parameter, which is upcasted to the node entity via the Drupal\node\ParamConverter\NodePreviewConverter()

See line 31 of node.routing.yml

entity.node.preview:
  path: '/node/preview/{node_preview}/{view_mode_id}'
  defaults:
    _controller: '\Drupal\node\Controller\NodePreviewController::view'
    _title_callback: '\Drupal\node\Controller\NodePreviewController::title'
  requirements:
    _node_preview_access: '{node_preview}'
  options:
    parameters:
      node_preview:
        type: 'node_preview'

Proposed resolution

Can we simply convert the parameter name in entity.node.preview from node_preview to node?

Remaining tasks

Patch, tests, ?

User interface changes

None

API changes

Unsure

Data model changes

None

πŸ› Bug report
Status

Needs work

Version

9.5

Component
Node systemΒ  β†’

Last updated less than a minute ago

No maintainer
Created by

πŸ‡ΊπŸ‡ΈUnited States jasonawant New Orleans, USA

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

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.

Production build 0.71.5 2024