function hook_entity_preload
Same name in other branches
- 9 core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_preload()
- 8.9.x core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_preload()
- 11.x core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_preload()
Act on an array of entity IDs before they are loaded.
This hook can be used by modules that need, for example, to return a different revision than the default one.
Parameters
array $ids: An array of entity IDs that have to be loaded.
string $entity_type_id: The type of entities being loaded (i.e. node, user, comment).
Return value
\Drupal\Core\Entity\EntityInterface[] An array of pre-loaded entity objects.
Related topics
2 functions implement hook_entity_preload()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
- entity_crud_hook_test_entity_preload in core/
modules/ system/ tests/ modules/ entity_crud_hook_test/ entity_crud_hook_test.module - Implements hook_entity_preload().
- workspaces_entity_preload in core/
modules/ workspaces/ workspaces.module - Implements hook_entity_preload().
1 invocation of hook_entity_preload()
- ContentEntityStorageBase::preLoad in core/
lib/ Drupal/ Core/ Entity/ ContentEntityStorageBase.php
File
-
core/
lib/ Drupal/ Core/ Entity/ entity.api.php, line 1041
Code
function hook_entity_preload(array $ids, $entity_type_id) {
$entities = [];
foreach ($ids as $id) {
$entities[] = my_module_swap_revision($id);
}
return $entities;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.