function user_node_load

Implements hook_node_load().

@todo Deprecated by $node->author, attached in \Drupal\node\NodeRenderController::buildContent(). Update code that depends on these properties.

File

drupal/core/modules/user/user.module, line 2345
Enables the user registration and login system.

Code

function user_node_load($nodes, $types) {

  // Build an array of all uids for node authors, keyed by nid.
  $uids = array();
  foreach ($nodes as $nid => $node) {
    $uids[$nid] = $node->uid;
  }

  // Fetch name and data for these users.
  $user_names = db_query("SELECT uid, name FROM {users} WHERE uid IN (:uids)", array(
    ':uids' => $uids,
  ))
    ->fetchAllKeyed();

  // Add these values back into the node objects.
  foreach ($uids as $nid => $uid) {
    $nodes[$nid]->name = $user_names[$uid];
  }
}