Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.1063
diff -u -p -r1.1063 common.inc
--- includes/common.inc	11 Dec 2009 16:56:10 -0000	1.1063
+++ includes/common.inc	15 Dec 2009 04:36:50 -0000
@@ -6426,6 +6426,46 @@ function entity_get_controller($entity_t
 }
 
 /**
+ * Invoke hook_entity_prepare_view().
+ *
+ * If adding a new entity similar to nodes, comments or users, you should
+ * invoke this function during the ENTITY_build_content() or
+ * ENTITY_build_multiple() phases of rendering to allow other modules to alter
+ * the objects during this phase. This is needed for situations where
+ * information needs to be loaded outside of ENTITY_load() - particularly
+ * when loading entities into one another - i.e. a user object into a node, due
+ * to the potential for unwanted side-effects such as caching and infinite
+ * recursion. By convention, entity_prepare_view() is called after
+ * field_attach_prepare_view() to allow entity level hooks to act on content
+ * loaded by field API.
+ * @see hook_entity_prepare_view()
+ *
+ * @param $entity_type
+ *   The type of entity, i.e. 'node', 'user'.
+ * @param $entities
+ *   The entity objects which are being prepared for view, keyed by object ID.
+ */
+function entity_prepare_view($entity_type, $entities) {
+  // To ensure hooks are only run once per entity, check for an
+  // entity_view_prepared flag and only process items without it.
+  // @todo: resolve this more generally for both entity and field level hooks.
+  $prepare = array();
+  foreach ($entities as $id => $entity) {
+    if (empty($entity->entity_view_prepared)) {
+      // Add this entity to the items to be prepared.
+      $prepare[$id] = $entity;
+
+      // Mark this item as prepared.
+      $entity->entity_view_prepared = TRUE;
+    }
+  }
+
+  if (!empty($prepare)) {
+    module_invoke_all('entity_prepare_view', $prepare, $entity_type);
+  }
+}
+
+/**
  * Performs one or more XML-RPC request(s).
  *
  * @param $url
Index: modules/comment/comment.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v
retrieving revision 1.815
diff -u -p -r1.815 comment.module
--- modules/comment/comment.module	11 Dec 2009 17:09:00 -0000	1.815
+++ modules/comment/comment.module	15 Dec 2009 04:36:50 -0000
@@ -852,6 +852,7 @@ function comment_build_content($comment,
 
   // Build fields content.
   field_attach_prepare_view('comment', array($comment->cid => $comment), $build_mode);
+  entity_prepare_view('comment', array($comment->cid => $comment));
   $comment->content += field_attach_view('comment', $comment, $build_mode);
 
   if (empty($comment->in_preview)) {
@@ -943,6 +944,7 @@ function comment_links($comment, $node) 
  */
 function comment_build_multiple($comments, $node, $build_mode = 'full', $weight = 0) {
   field_attach_prepare_view('comment', $comments, $build_mode);
+  entity_prepare_view('comment', $comments);
 
   $build = array(
     '#sorted' => TRUE,
Index: modules/node/node.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/node/node.module,v
retrieving revision 1.1181
diff -u -p -r1.1181 node.module
--- modules/node/node.module	11 Dec 2009 16:49:40 -0000	1.1181
+++ modules/node/node.module	15 Dec 2009 04:36:51 -0000
@@ -1232,6 +1232,7 @@ function node_build_content($node, $buil
   // @todo field_attach_prepare_view() is only invoked by node_build_multiple(),
   //   all other entities invoke it _here_.
   //field_attach_prepare_view('node', array($node->nid => $node), $build_mode);
+  entity_prepare_view('node', array($node->nid => $node));
   $node->content += field_attach_view('node', $node, $build_mode);
 
   // Always display a read more link on teasers because we have no way
@@ -2134,6 +2135,7 @@ function node_feed($nids = FALSE, $chann
  */
 function node_build_multiple($nodes, $build_mode = 'teaser', $weight = 0) {
   field_attach_prepare_view('node', $nodes, $build_mode);
+  entity_prepare_view('node', $nodes);
   $build = array();
   foreach ($nodes as $node) {
     $build['nodes'][$node->nid] = node_build($node, $build_mode);
Index: modules/rdf/rdf.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/rdf/rdf.module,v
retrieving revision 1.12
diff -u -p -r1.12 rdf.module
--- modules/rdf/rdf.module	11 Dec 2009 16:49:40 -0000	1.12
+++ modules/rdf/rdf.module	15 Dec 2009 04:36:51 -0000
@@ -580,6 +580,25 @@ function rdf_field_attach_view_alter(&$o
 }
 
 /**
+ * Implements hook_entity_prepare_view().
+ */
+function rdf_entity_prepare_view($entities, $entity_type) {
+  $uids = array();
+  // In the case of both nodes and comments, the full $account object for the
+  // author is needed in rdf_preprocess_username(), however this is not
+  // available from node_load() or comment_load(). If the users are loaded
+  // for the first time in rdf_preprocess_username() this will issue an
+  // individual user_load() for each account, so pre-load the users needed
+  // here where we can take advantage of user_load_multiple().
+  if ($entity_type == 'node' || $entity_type == 'comment') {
+    foreach ($entities as $entity) {
+      $uids[$entity->uid] = $entity->uid;
+    }
+    user_load_multiple($uids);
+  }
+}
+
+/**
  * Wraps a template variable in an HTML element with the desired attributes.
  *
  * This is called by rdf_process() shortly before the theme system renders
Index: modules/system/system.api.php
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.api.php,v
retrieving revision 1.109
diff -u -p -r1.109 system.api.php
--- modules/system/system.api.php	13 Dec 2009 13:06:45 -0000	1.109
+++ modules/system/system.api.php	15 Dec 2009 04:36:51 -0000
@@ -212,6 +212,28 @@ function hook_admin_paths_alter(&$paths)
 }
 
 /**
+ * Act on entities as they are being prepared for view.
+ *
+ * Allows you to operate on multiple entities as they are being prepared for
+ * view. Only use this if attaching the data during the entity_load() phase
+ * is not appropriate, for example when attaching other 'entity' style objects.
+ *
+ * @param $entities
+ *   The entities keyed by entity ID.
+ * @param $type
+ *   The type of entities being loaded (i.e. node, user, comment).
+ */
+function hook_entity_prepare_view($entities, $type) {
+  // Load a specific node into the user object for later theming.
+  if ($type == 'user') {
+    $nodes = mymodule_get_user_nodes(array_keys($entities));
+    foreach ($entities as $uid => $entity) {
+      $entity->user_node = $nodes[$uid];
+    }
+  }
+}
+
+/**
  * Perform periodic actions.
  *
  * This hook will only be called if cron.php is run (e.g. by crontab).
Index: modules/taxonomy/taxonomy.pages.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.pages.inc,v
retrieving revision 1.45
diff -u -p -r1.45 taxonomy.pages.inc
--- modules/taxonomy/taxonomy.pages.inc	13 Nov 2009 09:24:06 -0000	1.45
+++ modules/taxonomy/taxonomy.pages.inc	15 Dec 2009 04:36:51 -0000
@@ -31,6 +31,7 @@ function taxonomy_term_page($term) {
   drupal_add_css(drupal_get_path('module', 'taxonomy') . '/taxonomy.css');
 
   field_attach_prepare_view('taxonomy_term', array($term->tid => $term), 'full');
+  entity_prepare_view('taxonomy_term', array($term->tid => $term));
   $build = array();
   $build += field_attach_view('taxonomy_term', $term);
   $build['term_description'] = array(
Index: modules/user/user.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.module,v
retrieving revision 1.1089
diff -u -p -r1.1089 user.module
--- modules/user/user.module	7 Dec 2009 03:45:16 -0000	1.1089
+++ modules/user/user.module	15 Dec 2009 04:36:51 -0000
@@ -2171,6 +2171,7 @@ function user_build_content($account, $b
 
   // Build fields content.
   field_attach_prepare_view('user', array($account->uid => $account), $build_mode);
+  entity_prepare_view('user', array($account->uid => $account));
   $account->content += field_attach_view('user', $account, $build_mode);
 
   // Populate $account->content with a render() array.
