diff --git a/includes/entity.inc b/includes/entity.inc index e80ce3b..a67d420 100644 --- a/includes/entity.inc +++ b/includes/entity.inc @@ -363,13 +363,35 @@ class DrupalDefaultEntityController implements DrupalEntityControllerInterface { // Call hook_TYPE_load(). The first argument for hook_TYPE_load() are // always the queried entities, followed by additional arguments set in // $this->hookLoadArguments. - $args = array_merge(array($queried_entities), $this->hookLoadArguments); + $args = array_merge(array($queried_entities)); + // Figure out whether the load arguments are nested inside a $ids_dump keyed + // sub-array as a workaround for multiple concurrent entity loads. + $ids_dump = $this->idsDump($queried_entities); + if (isset($this->hookLoadArguments[$ids_dump])) { + $args = array_merge($args, $this->hookLoadArguments[$ids_dump]); + } + elseif (!empty($this->hookLoadArguments)) { + $args = array_merge($args, $this->hookLoadArguments); + } foreach (module_implements($this->entityInfo['load hook']) as $module) { call_user_func_array($module . '_' . $this->entityInfo['load hook'], $args); } } /** + * Dump all entity IDs into a unique string. This is needed to make + * hookLoadArguments work with multiple concurrent entity loads. + * + * @param $entities + * The entities array as queried. + */ + protected function idsDump($entities) { + $ids = array_keys($entities); + return implode(',', $ids); + } + + + /** * Gets entities from the static cache. * * @param $ids diff --git a/modules/node/node.module b/modules/node/node.module index 1d88834..dedd800 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -4172,8 +4172,10 @@ class NodeController extends DrupalDefaultEntityController { // Besides the list of nodes, pass one additional argument to // hook_node_load(), containing a list of node types that were loaded. $argument = array_keys($typed_nodes); - $this->hookLoadArguments = array($argument); + $ids_dump = $this->idsDump($nodes); + $this->hookLoadArguments[$ids_dump] = array($argument); parent::attachLoad($nodes, $revision_id); + unset($this->hookLoadArguments[$ids_dump]); } protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE) {