Views contextual filter not passed to AJAX callback URL when used with entity reference view attached to ajax based field widget

Created on 20 April 2018, over 6 years ago
Updated 10 July 2024, about 2 months ago

Problem/Motivation

I've got two content types. Let's call them X and Y.

X has an entity reference field, pointing to nodes of content type Y. If I use the default view, things seem to work fine.

I then want to create an interesting/complex entity reference view that works from the edit page for a node of type X (e.g. /node/1234/edit), that takes the nid of the current node (i.e. 1234) as uses it in a parameter for the view.

My entity reference view works just fine. I manually enter the contextual filter in the view (i.e. 1234) and the results are exactly as I expect.

However, I can't seem to figure out setting up the Contextual Filter so that this works within /node/1234/edit.

I've tried the following:

Content: ID. When the Filter Value is not available: Provide Default Value: Content ID from URL

Content: ID. When the Filter Value is not available: Provide Default Value: Raw value from URL (Path Component 2)

Neither seems to work. Within the entity reference field on /node/1234/edit, no results are returned. If I disable this Contextual Filter. (i.e. set "Display all results for the specified field"), the view works fine on the node edit page.

Any ideas what I'm doing wrong here? Any ideas on how I can help diagnose it (return the value that contextual filter is seeing in the entity reference result?)

Thanks in advance!

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ’¬ Support request
Status

Active

Version

11.0 πŸ”₯

Component
ViewsΒ  β†’

Last updated about 12 hours ago

Created by

πŸ‡¨πŸ‡¦Canada TrevorBradley

Live updates comments and jobs are added and updated live.
  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

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.

  • πŸ‡¬πŸ‡§United Kingdom welly

    My concern with "works as designed" is using different field widgets exhibits different behaviour.

    For example, if you create the entity reference view display, add a contextual filter (Content from URL) and attach it to a field and set the field widget to select or checkboxes or similar then this works as expected - the contextual filter behaves exactly as you'd expect and excludes the current node from the field widget.

    However, if you then change this to Autocomplete the behaviour changes - no nodes are returned. I think this needs some consideration as to whether this is broken - to me it is.

    While the patch/sandbox module does provide a fix for this, I think this should be the responsibility of core for the behaviour to be consistent across different field widgets.

  • πŸ‡¬πŸ‡§United Kingdom welly

    I've created an example of this behaviour here:

    https://master-763xidikw6xdqu8pd9mzr8fbjg3acetr.tugboatqa.com/

    You should be able to login with the usual simplytest.me credentials (admin/admin) and if you edit a page:

    https://master-763xidikw6xdqu8pd9mzr8fbjg3acetr.tugboatqa.com/node/1/edit

    you will see one field with a select widget excludes the current node, the second field using autocomplete does not return any nodes.

    This shows broken behaviour to me.

  • πŸ‡¬πŸ‡§United Kingdom welly

    I've attached a config export from the above simplytest.me environment so we can re-build the demo site if needs be.

  • πŸ‡¬πŸ‡§United Kingdom AaronMcHale Edinburgh, Scotland

    @devkinetic not a duplicate of those issue. Those issues are about making the taxonomy style exposed filter available for all entity types, whereas this issue is specifically about when using an Ajax-based field widget for an entity reference field, it not being possible to exclude the current entity.

    On one hand you could argue that this works as designed, because strictly speaking when using an Ajax field widget the current URL is the Ajax request URL, rather than the URL of the page the user is on. However, I don't think that's a helpful way of looking at it, because the result is that the entity reference view behaves differently depending on the field widget that is being used.

    Let's take the example of a contrib module that provides an entity reference view, the View has no knowledge of where its going to be used, the users of this module should be able to use the entity reference View and field with any of our Core supported widget and expect consistent behavior.

    Therefor, I would argue that this is a problem that Core needs to address because the result is inconsistent behavior with a supported Core feature. I don't think the answer to that should be to say this is a problem to solve in contrib.

    Thanks,
    -Aaron

  • πŸ‡¬πŸ‡§United Kingdom welly

    Updated title for clarity (perhaps?)

  • πŸ‡¬πŸ‡§United Kingdom welly

    (possibly) slightly better title

  • πŸ‡³πŸ‡ΏNew Zealand quietone New Zealand

    Drupal 8 is no longer supported. Moving to the main development branch, which is 11.x.

Production build 0.71.5 2024