Reference external entities using REST storage client

Created on 1 August 2025, 2 days ago

This is a follow up to the findings in #3045877 ✨ Support Drupal's Entity Reference field type concept on external data source. Active .

The goal is to reference an external entity by ID in an entity reference field using the autocomplete widget.

https://www.drupal.org/project/external_entities/issues/3056530 β†’

I had a look and I have a good and a "bad" news. The good news is that it IS possible to reference external entities using a regular entity reference field, without any modification or trick. It already works. That was the good news... :-)

The "bad" news is that the storage client(s) used to fetch external entities must support the 'IN' operator in query filtering. If it does not, there's no way for the default Drupal entity reference validator to fetch all the referenced external entities and validate their IDs. That's why @mortona2k got issue referencing external entities.

When you use REST services, you don't have a "standard" query that returns all the valid IDs, given a list of IDs. For the builtin REST client, there is a way to get around that but with a real cost. On the storage client settings, in the "filtering" section, you may check the box "Enable Drupal-side filtering". This will support Drupal filters such as "IN" as well as others. The problem will be that the REST client will need to fetch ALL the external entities from the REST service to filter them on the client side, which can be a real problem if there are many and/or if the service is slow. You may use cache (and pre-populate it using the XNTT manager) but it may not be an ideal solution.

Regarding tests, the external entity reference field is already tested appropriately (SimpleExternalEntityTest::testSimpleExternalEntity()). No need to add new tests.

So, I'll close that issue as "Working as designed". For the very specific case of REST services and the "IN" filter operator, one of you may create a new issue that would be a "feature request" for the REST client. I don't see so far an easy way to add that feature so propose solutions if you create that feature request! :)

✨ Feature request
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States mortona2k Seattle

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

Comments & Activities

  • Issue created by @mortona2k
  • πŸ‡ΊπŸ‡ΈUnited States mortona2k Seattle
  • @mortona2k opened merge request.
  • πŸ‡ΊπŸ‡ΈUnited States mortona2k Seattle

    I'm not sure how to fix this at the entity level. Here's an entity reference selection plugin that works for the specific external entity type.

  • πŸ‡«πŸ‡·France guignonv Montpellier

    As we chatted on slack, I think I'll implement a way to support the 'IN' operator on the identifier by default for any storage client. That would be a generic solution that would avoid enabling Drupal-side filtering for REST clients, which can be problematic.

Production build 0.71.5 2024