Inaccurate Canvas previews for Views blocks that use Views Argument handler plugins
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3578150. -->
Reported by: [tedbow](https://www.drupal.org/user/240860)
Related to !711
>>>
<h3 id="overview">Overview</h3>
<p>Views and Canvas could be a very powerful combination! </p>
<p>For example, you could make a View block that displays teasers of other articles by the same author and place that View on the Full Content Template for articles in Canvas. When <span class="drupalorg-gitlab-issue-link drupalorg-gitlab-link-wrapper"><a href="https://git.drupalcode.org/project/canvas/-/work_items/3574412" class="drupalorg-gitlab-link">https://git.drupalcode.org/project/canvas/-/work_items/3574412</a></span> is done, you could also use Canvas to customize the display of those teasers.</p>
<p>This sort of works now, but when you place the View block in the Canvas preview, it will not get the node ID from the route context, so it will not be rendered. But if you publish the template, the View block will be rendered.</p>
<p>So I think this is a bug rather than a feature request, because the content template preview acts differently than the full view of the node.</p>
<p>This is because \Drupal\node\Plugin\views\argument_default\Node::getArgument, \Drupal\user\Plugin\views\argument_default\User::getArgument and other places in core hard-code `node`, `user` and other entity types. This does not work with our route</p>
<pre>canvas.api.form.component_instance.content_template:<br> <<: *component_instance_form_route<br> path: '/canvas/api/v0/form/component-instance/content_template/{entity}/{preview_entity}'<br> requirements:<br> <<: *component_instance_form_route_requirements<br> _canvas_preview_entity_view_access: TRUE<br> options:<br> <<: *component_instance_form_route_options<br> parameters:<br> entity:<br> type: entity:content_template<br> preview_entity:<br> # @see \Drupal\canvas\Routing\ContentTemplatePreviewEntityConverter<br> type: canvas_content_template_preview_entity</pre><p>
where `preview_entity` will be different types of entities based on what the target type of the template is (though we only support nodes now).<br>
Screenshots<br>
Setup out basic page with "other node" references field<br>
views setup<br>
<img src="https://www.drupal.org/files/issues/2026-03-17/view-contextual.png" alt="contextual filter setup"><br>
adding view block to template in 1.x<br>
<img src="https://www.drupal.org/files/issues/2026-03-17/view-arg-1x.gif" alt="adding view block in 1.x shows no results"><br>
See "User interface changes" below for same with MR</p>
<h3 id="proposed-resolution">Proposed resolution</h3>
<p>Add a route enhancer that automatically adds a node, user, or other entity type default based on the template target entity type.</p>
<p>Even though we only support nodes in templates now, Views default arguments like \Drupal\user\Plugin\views\argument_default\User::getArgument allow filtering on the author of a node, so this will allow filtering views by author, similarly with \Drupal\taxonomy\Plugin\views\argument_default\Tid::getArgument.</p>
<h3 id="ui-changes">User interface changes</h3>
<p>View blocks that rely on entity IDs from route context will render in preview.<br>
<img src="https://www.drupal.org/files/issues/2026-03-17/view-arg-mr.gif" alt="adding view block in MR shows result"></p>
issue