function hook_entity_preload

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_preload()
  2. 10 core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_preload()
  3. 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
Gathers entities from a 'preload' step.

File

core/lib/Drupal/Core/Entity/entity.api.php, line 1048

Code

function hook_entity_preload(array $ids, $entity_type_id) {
    $entities = [];
    foreach ($ids as $id) {
        $entities[] = mymodule_swap_revision($id);
    }
    return $entities;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.