loadMultiple() with no IDs breaks when hook_entity_preload() returns an array of entities

Created on 2 February 2023, over 1 year ago
Updated 6 February 2023, over 1 year ago

Problem/Motivation

Using loadMultiple without specifying IDs when a workspace is active causes an error in EntityStorageBase::loadMultiple().

This causes a problem if you need to load all entities while a workspace is active. A work-around is to find out every entity ID before, and pass that to loadMultiple.

TypeError: array_diff_key(): Argument #1 ($array) must be of type array, bool given

/var/www/html/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php:302
/var/www/html/web/core/lib/Drupal/Core/Entity/EntityBase.php:49

This error occurs if no IDs are given because `$flipped_ids` is FALSE, and array_diff_key only works on arrays.

Steps to reproduce

Activate a workspace, then call any loadMultiple function when there is at least one entity of that type in the workspace. Eg, Node::loadMultiple or EntityStorageInterface::loadMultiple.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Needs work

Version

10.1 ✨

Component
EntityΒ  β†’

Last updated about 13 hours ago

Created by

πŸ‡¨πŸ‡¦Canada tbradbury

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024