Using entity reference filter in a non-exposed view filter as Autocomplete causes error.

Created on 11 June 2025, 24 days ago

Problem/Motivation

This module has worked well for us to enable core's autocomplete in exposed views filters, but if we edit a view with a non-exposed filter which uses an entity reference filter, the UI appears to work but when saving the setting the following error is generated in the JS console:

Object { message: "\nAn AJAX HTTP error occurred.\nHTTP Result Code: 500\nDebugging information follows.\nPath: /admin/structure/views/ajax/handler/test1/default/filter/field_articles_target_id\nStatusText: error\nResponseText: The website encountered an unexpected error. Try again later.", name: "AjaxError", stack: "@https://d10.lndo.site/sites/default/files/js/js_V5T4MYG3G8TZakOERlAa3wOfK4csk6YAM1OvBwwok0E.js?scope=footer&delta=0&language=en&theme=claro&include=eJyFjlEOwyAMQy9E4Qw7SWUgqrJlgCDtevx1U1HFfvbnPDuyPS9z4ULOn8IEQc0u1rVAbMI2KXwzISelXVdIty4yCafHn4jmLB71CFXqNoLyRt_vgYcsgtJogJEhebG4Yx94Uyi1AR2DhWLFYs5W19t_bkstoNAtPjmZjenV5pVdFxYf_gZlHG_S:242:2411\n@https://d10.lndo.site/sites/default/files/js/js_V5T4MYG3G8TZakOERlAa3wOfK4csk6YAM1OvBwwok0E.js?scope=footer&delta=0&language=en&theme=claro&include=eJyFjlEOwyAMQy9E4Qw7SWUgqrJlgCDtevx1U1HFfvbnPDuyPS9z4ULOn8IEQc0u1rVAbMI2KXwzISelXVdIty4yCafHn4jmLB71CFXqNoLyRt_vgYcsgtJogJEhebG4Yx94Uyi1AR2DhWLFYs5W19t_bkstoNAtPjmZjenV5pVdFxYf_gZlHG_S:242:19963\n" }
js_V5T4MYG3G8TZakOERlAa3wOfK4csk6YAM1OvBwwok0E.js:242:2411

Steps to reproduce

  1. Install Drupal 10.4.8.
  2. Install views_core_entity_reference 1.0.0-alpha3 and enable.
  3. Add a test field to default Page content type to reference Article content (unlimited, not required).
  4. Create a bunch of sample Articles and sample Pages, which reference those Articles.
  5. Create a view of Pages using default options.
  6. Add a filter criteria to the view.
  7. Select the test field created in step 3.
  8. Select "Content type" of Article.
  9. Select "Selection type" of Autocomplete.
  10. Leave operator as "is one of."
  11. In the Autocomplete field, type a character and select a result. (If use Select List it will work as expected.)
  12. Click Apply.
  13. Error above will be generated in JS console and form will not close.
  14. View is now broken and can't be edited. Clearing the tempstore for the view will let you back in:

    drush php:eval "\Drupal::keyValueExpirable('tempstore.shared.views')->delete('test1');"

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States msielski

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

Comments & Activities

  • Issue created by @msielski
  • πŸ‡ΊπŸ‡ΈUnited States msielski
  • πŸ‡ΊπŸ‡ΈUnited States msielski
  • πŸ‡¬πŸ‡§United Kingdom scott_euser

    Hi there!

    I'm not sure though where this can be addressed - I'm thinking maybe further up the inheritance chain in EntityReference class?

    Correct yeah, all this module does is alter views data to make use of the Entity Reference filter in core (ie, opts in to it https://git.drupalcode.org/project/views_core_entity_reference/-/blob/1....). It does not actually provide the entity reference filter. So the issue would need to be raised in Drupal Core itself if you have found a bug with it.

    As a workaround you can specifically only opt some fields into the new filter per the "Alternatives to using this module" instructions on the module homepage https://www.drupal.org/project/views_core_entity_reference β†’

    Hope that helps! I'll move it to works as designed here, but rather than create a separate issue you could also decide to move the issue 'Project' entirely over to core and re-open.

  • πŸ‡ΊπŸ‡ΈUnited States msielski

    @scott_euser - thank you for your reply. Yes, did try the workaround you suggested but unfortunately the field we are interested in is used both as an exposed filter some places and as non-exposed in others, so once we alter it to work as an exposed filter it breaks in its other case.

    I did my best to read over #3347343 and I don't see a lot of discussion about non-exposed filters. I can raise this as a core issue. Do you think it'd be better to add a comment to the above thread or a brand new issue? I only ask because the feature is currently somewhat under the radar. Thank you.

Production build 0.71.5 2024