Closed (fixed)
Project:
Entity Browser
Version:
8.x-2.x-dev
Component:
Widget plugins
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
3 Oct 2019 at 12:48 UTC
Updated:
23 Aug 2026 at 07:45 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
anwoon commentedComment #3
anwoon commentedComment #4
anwoon commentedComment #5
judapriestGot the same error
Step to reproduce :
Pacth seems to work fine.
Comment #6
leontin commentedYour patch didn't work for me.
Because you return an empty array, instead a Entity, I got another error:
I propose another patch.
Comment #7
avpadernoComment #10
avpadernoComment #11
soutams commentedWe are facing the same issue.
Is there any solution/patch available?
I'm using Entity Browser 2.9 version.
We are getting below error message
TypeError: Drupal\Core\Entity\EntityRepository::getTranslationFromContext(): Argument #1 ($entity) must be of type Drupal\Core\Entity\EntityInterface, null given, called in /docroot/modules/contrib/entity_browser/src/Element/EntityBrowserElement.php on line 259 in Drupal\Core\Entity\EntityRepository->getTranslationFromContext() (line 93 of /docroot/core/lib/Drupal/Core/Entity/EntityRepository.php)
Comment #12
mediabounds commentedWe're also encountering this issue essentially with same the steps as in #5 (although for us it as with nodes).
I'm attaching a slightly different version of the patch in #6.
When processing the entity IDs, if it encounters one that doesn't exist, it just skips over it. This seems (to me) to be consistent with how Drupal core works on entity reference fields.
Comment #13
soutams commented@mediabounds,
https://www.drupal.org/files/issues/2023-10-20/3085476-12.patch after applying this patch the mentioned issue got resolved, but still not able to submit the node. It is giving "media:null" error. Exact error "The referenced entity (media: null) does not exist."
I'm trying to embed youtube video in an entity reference field. But facing all these issues.
I'm using Entity Browser 2.9 version.
Comment #17
nicocin commentedPatch for 2.15.
Comment #18
benstallings commentedClaude Code says (emphasis added):
What it does: Two changes bundled together:
1. Adds a null check after load(). If an entity no longer exists (deleted between selection and processing), the current code passes null to getTranslationFromContext(), which throws a fatal error. The patch skips missing entities with if ($entity). This is a good fix for a real crash scenario.
2. Removes getTranslationFromContext(). The current code returns translated entities; the patch returns untranslated ones. This is a behavioral regression — multilingual sites depend on this to get entities in the current language context. Removing it silently breaks translation support.
Other issues:
- Indentation bug. The $entities = []; line is indented with 2 spaces instead of the surrounding 4. Would fail phpcs.
- list() vs [] style. The patch changes [$a, $b] = ... to list($a, $b) = .... The short syntax is the modern PHP convention and what the codebase already uses. This is a step backward.
- Commit message is "aa". Not useful.
What it should be: Keep the null check, keep the translation call, fix the indentation:
Summary: The null safety fix is needed, but the patch removes translation support as a side effect. Needs rework to preserve getTranslationFromContext().
Comment #19
benstallings commentedComment #20
anybodyComment #22
benstallings commented1. Translation support restored — getTranslationFromContext() is back, now wrapped in the null check so deleted entities are skipped instead of crashing the call.
2. Indentation fixed — the rewritten block uses the surrounding 2-space Drupal indentation.
3. Modern array destructuring — kept [$entity_type, $entity_id] = explode(':', $item) rather than reverting to list().
4. Commit message — reworded to follow the standard Issue #NNNNN by user: format.
One behavior change worth calling out explicitly: switching from array_map to a foreach with $entities[] means missing entities are silently dropped and the result is reindexed sequentially, where the previous code would have returned NULL entries (and then crashed on them). I checked the callers in EntityReferenceBrowserWidget::getEntities() / ::getCurrentUserInputEntities() and entity_browser_entity_form_*_submit() — all of them consume the result as a flat list and don't rely on the keys, so dropping missing entries should be safe. Flagging it here in case anyone (or anybody) wants to confirm before RTBC.
Comment #23
benstallings commentedComment #24
avpadernoComment #26
berdirMerging.
Comment #28
berdir