Problem/Motivation
It's not immediately clear whether hook_entity_load() is invoked or not when the entity storage has the entity in the cache.
It turns out it's not.
Steps to reproduce
Proposed resolution
Document this in the general CRUD topic and in the two flavours of the hook.
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
Issue fork drupal-3642896
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
mohamed-ghoneim commentedI reviewed MR !18133 against the current code on the main branch.
The new documentation matches the actual behavior:
- In EntityStorageBase::loadMultiple(), entities returned by getFromStaticCache() are added straight to $entities. Only $queried_entities (loaded through doLoadMultiple()) go through postLoad(), so hook_entity_load() and hook_ENTITY_TYPE_load() are not invoked for statically cached entities.
- For content entities loaded from the persistent cache, postLoad() still runs (see the comment in ContentEntityStorageBase about running post load for entities retrieved from the persistent cache). So the sentence about the persistent cache is correct too.
- All three places from the proposed resolution are covered: the entity_crud topic, hook_entity_load() and hook_ENTITY_TYPE_load().
One question: entities returned by preLoad() (for example through hook_entity_preload()) also skip postLoad() in loadMultiple(). Is that worth mentioning as well, or is it out of scope here?
The MR has been open for a while but the issue is still Active, so I'm moving it to Needs review.
Comment #5
smustgrave commentedCan ask questions without needs review believe.
But also the comment read as Ai without disclosure https://www.drupal.org/docs/develop/issues/issue-procedures-and-etiquett...
Another member of your company mentioned using AI too so making my assumption stronger
Please disclose use of AI on all submissions