Autocomplete field ignores [node:*] token in entity reference view after Drupal 10.4 Upgrade

Created on 19 June 2025, 15 days ago

Problem/Motivation

After upgrading from Drupal 10.3 to 10.4, entity reference fields using the
“Views: Filter by an entity reference view” selection method no longer apply contextual filters
when the default value is set using a token (e.g., [node:field_reference]).

While the view behaves correctly in the preview (the contextual filter resolves as expected), the
autocomplete field on the edit form ignores the contextual argument. This results in an
unfiltered list of all possible entities instead of a scoped list based on form context.

This impacts editorial workflows that depend on context-aware filtering (e.g., selecting a related item based
on another selected field).

Not sure if this should have been a bug or feature request?

Steps to reproduce

  1. Create two content types: Parent and Child.
  2. On Child, create:
    • An entity reference field (e.g., field_parent_ref) referencing Parent.
    • Another reference field (e.g., field_related_item) which should be scoped to the parent.
  3. Create a View:
    • Base it on the target of field_related_item (e.g., nodes, terms, or users).
    • Add a contextual filter (e.g., field_parent_ref).
    • Set the default value to [node:field_parent_ref].
    • Add an Entity Reference display.
  4. Configure field_related_item to use this view.
  5. Create and save a Child node with a selected Parent.
  6. Edit the same Child node.

Expected: Autocomplete results for field_related_item are filtered by the parent.

Actual: Results are unfiltered; all entities are shown.

Proposed resolution

During entity editing, the context (e.g., the current node) is not passed to the view when resolving token-based
default arguments. This appears to be a regression introduced in or around Drupal 10.4.

A workaround using hook_views_pre_view() can inject the needed contextual argument manually,
but this is not ideal.

A proper fix would:

  • Ensure the edited entity is passed to the view used for entity reference autocomplete.
  • Support token-based default arguments like [node:field_*] in that context.
🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇺🇸United States webdrips

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

Comments & Activities

Production build 0.71.5 2024