protected function NodeStorageController::attachLoad

Overrides Drupal\Core\Entity\DatabaseStorageControllerNG::attachLoad().

Overrides DatabaseStorageControllerNG::attachLoad

File

drupal/core/modules/node/lib/Drupal/node/NodeStorageController.php, line 35
Definition of Drupal\node\NodeStorageController.

Class

NodeStorageController
Controller class for nodes.

Namespace

Drupal\node

Code

protected function attachLoad(&$queried_entities, $load_revision = FALSE) {
  $nodes = $this
    ->mapFromStorageRecords($queried_entities, $load_revision);

  // Create an array of nodes for each content type and pass this to the
  // object type specific callback. To preserve backward-compatibility we
  // pass on BC decorators to node-specific hooks, while we pass on the
  // regular entity objects else.
  $typed_nodes = array();
  foreach ($nodes as $id => $node) {
    $queried_entities[$id] = $node
      ->getBCEntity();
    $typed_nodes[$node
      ->bundle()][$id] = $queried_entities[$id];
  }
  if ($load_revision) {
    field_attach_load_revision($this->entityType, $queried_entities);
  }
  else {
    field_attach_load($this->entityType, $queried_entities);
  }

  // Call object type specific callbacks on each typed array of nodes.
  foreach ($typed_nodes as $node_type => $nodes_of_type) {

    // Retrieve the node type 'base' hook implementation based on a Node in
    // the type-specific stack.
    if ($function = node_hook($node_type, 'load')) {
      $function($nodes_of_type);
    }
  }

  // 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,
  );

  // Call hook_entity_load().
  foreach (module_implements('entity_load') as $module) {
    $function = $module . '_entity_load';
    $function($queried_entities, $this->entityType);
  }

  // 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);
  foreach (module_implements($this->entityType . '_load') as $module) {
    call_user_func_array($module . '_' . $this->entityType . '_load', $args);
  }
}