Problem/Motivation
In D8.7 and D8.8, Drupal\Core\Entity\ContentEntityStorageBase::cleanIds switched to loading field definitions with getActiveFieldStorageDefinitions, which fails to return all definitions in the event an external entity is not cached locally. See #3 below for more details.
Proposed resolution
Override ContentEntityStorageBase::cleanIds and use getFieldStorageDefinitions instead.
Remaining tasks
Submit patch.
Review.
User interface changes
None.
API changes
None.
Data model changes
None.
Release notes snippet
TBD.
Original report by ericras
I'm following the examples and also building my own storage client.
In each case I get a fatal error:
Error: Call to a member function getType() on null in /core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php on line 990
which comes from the call to cleanIds() in ExternalEntityStorage:
protected function getFromExternalStorage(array $ids) {
$entities = [];
if (!empty($ids)) {
// Sanitize IDs. Before feeding ID array into buildQuery, check whether
// it is empty as this would load all entities.
$ids = $this->cleanIds($ids);
}
....
Taking that out 'fixes' the problem. I'm not sure if sanitizing is necessary there, and I'm also unsure of how to fix it if its left in.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | external_entities-override_cleanids-3053465-7.patch | 1.07 KB | clemens.tolboom |
| #5 | external_entities-override_cleanids-3053465-5.patch | 1.08 KB | chris burge |
Comments
Comment #2
clemens.tolboomI got the same error while trying #3055615: Self reflect to Drupal using REST API.
Does it help removing fields?
Comment #3
chris burge commentedThis bug is caused by #2554235: Make the content entity storage and entity query use the last installed definitions instead of the ones living in code, which was committed to D8.7 and D8.8 on 22 March, 2019.
The following change was made to
core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php:Per the API docs for EntityFieldManager::getActiveFieldStorageDefinitions, this method return "the active field storage definitions for a content entity type." This causes an issue in External Entities.
If the external entity is cached locally, then no problem. If the external entity is not cached locally, then definitions are missing. Specifically, we need the 'id' definition.
See comments in code below to step through cleanIds():
If we use
getFieldStorageDefinitionsinstead, then we get all of the definitions and no error. I'm going to be submitting a patch to override thecleanIdsmethod.I've changed the priority to critical because this bug renders the module unusable in D8.7+ and there are no workarounds.
Comment #4
chris burge commentedComment #5
chris burge commentedComment #6
chris burge commentedComment #7
clemens.tolboomI had to change $entityKey in 'id'
+ $field_name = $this->entityType->getKey('id');and can confirm this fixes my wikipedia test.So will commit soon
Comment #9
clemens.tolboom@Chris Burge thanks for fixing.
Comment #10
clemens.tolboomStrange as 'author' is not remembered.
Comment #11
clemens.tolboom