diff --git a/core/lib/Drupal/Core/Entity/EntityStorageBase.php b/core/lib/Drupal/Core/Entity/EntityStorageBase.php index 57f8969f87..137e68210e 100644 --- a/core/lib/Drupal/Core/Entity/EntityStorageBase.php +++ b/core/lib/Drupal/Core/Entity/EntityStorageBase.php @@ -4,6 +4,7 @@ use Drupal\Core\Entity\Query\QueryInterface; use Drupal\Core\Cache\MemoryCache\MemoryCacheInterface; +use Drupal\Core\Extension\Hook\FunctionInvoker; /** * A base entity storage class. @@ -332,8 +333,12 @@ public function loadMultiple(array $ids = NULL) { protected function postLoad(array &$entities) { $entity_class = $this->entityClass; $entity_class::postLoad($this, $entities); - $this->moduleHandler()->invokeAll('entity_load', [$entities, $this->entityTypeId]); - $this->moduleHandler()->invokeAll($this->entityTypeId . '_load', [$entities]); + $this->moduleHandler->invokeAllWith('entity_load', new FunctionInvoker(function ($hook_implementation) use (&$entities) { + $hook_implementation($entities, $this->entityTypeId); + })); + $this->moduleHandler->invokeAllWith($this->entityTypeId . '_load', new FunctionInvoker(function ($hook_implementation) use (&$entities) { + $hook_implementation($entities); + })); } /** diff --git a/core/lib/Drupal/Core/Entity/entity.api.php b/core/lib/Drupal/Core/Entity/entity.api.php index ebbbf63bdb..a46b90ce98 100644 --- a/core/lib/Drupal/Core/Entity/entity.api.php +++ b/core/lib/Drupal/Core/Entity/entity.api.php @@ -966,7 +966,7 @@ function hook_ENTITY_TYPE_revision_create(Drupal\Core\Entity\EntityInterface $ne * hook_entity_storage_load() should be used to load additional data for * content entities. * - * @param \Drupal\Core\Entity\EntityInterface[] $entities + * @param \Drupal\Core\Entity\EntityInterface[] &$entities * The entities keyed by entity ID. * @param string $entity_type_id * The type of entities being loaded (i.e. node, user, comment). @@ -974,7 +974,7 @@ function hook_ENTITY_TYPE_revision_create(Drupal\Core\Entity\EntityInterface $ne * @ingroup entity_crud * @see hook_ENTITY_TYPE_load() */ -function hook_entity_load(array $entities, $entity_type_id) { +function hook_entity_load(array &$entities, $entity_type_id) { foreach ($entities as $entity) { $entity->foo = mymodule_add_something($entity); } diff --git a/core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module b/core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module index 0325dbdbb4..baf0604cc8 100644 --- a/core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module +++ b/core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module @@ -178,7 +178,7 @@ function entity_crud_hook_test_user_insert() { /** * Implements hook_entity_load(). */ -function entity_crud_hook_test_entity_load(array $entities, $type) { +function entity_crud_hook_test_entity_load(array &$entities, $type) { $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called for type ' . $type); } diff --git a/core/modules/views/tests/modules/views_entity_test/views_entity_test.module b/core/modules/views/tests/modules/views_entity_test/views_entity_test.module index 7d80e84c78..fc046b88ae 100644 --- a/core/modules/views/tests/modules/views_entity_test/views_entity_test.module +++ b/core/modules/views/tests/modules/views_entity_test/views_entity_test.module @@ -51,7 +51,7 @@ function views_entity_test_entity_field_access($operation, FieldDefinitionInterf * * @see \Drupal\Tests\views\Kernel\Handler\FieldFieldTest::testSimpleExecute() */ -function views_entity_test_entity_load(array $entities, $entity_type_id) { +function views_entity_test_entity_load(array &$entities, $entity_type_id) { if ($entity_type_id === 'entity_test') { // Cast the value of an entity field to be something else than a string so // we can check that diff --git a/core/modules/workspaces/workspaces.module b/core/modules/workspaces/workspaces.module index 8345b8bb3a..f279c43893 100644 --- a/core/modules/workspaces/workspaces.module +++ b/core/modules/workspaces/workspaces.module @@ -59,7 +59,7 @@ function workspaces_form_alter(&$form, FormStateInterface $form_state, $form_id) /** * Implements hook_entity_load(). */ -function workspaces_entity_load(array $entities, $entity_type_id) { +function workspaces_entity_load(array &$entities, $entity_type_id) { return \Drupal::service('class_resolver') ->getInstanceFromDefinition(EntityOperations::class) ->entityLoad($entities, $entity_type_id);