From 0dcff9678a0990ccf6c9333016d9472dfbac76b7 Mon Sep 17 00:00:00 2001
From: Bram Goffings <bramgoffings@gmail.com>
Date: Wed, 13 Jun 2012 11:47:50 +0200
Subject: [PATCH] entity view alter

---
 core/modules/comment/comment.module   |    5 ++---
 core/modules/entity/entity.api.php    |   12 +++++-------
 core/modules/node/node.module         |    5 ++---
 core/modules/taxonomy/taxonomy.module |    2 +-
 core/modules/user/user.module         |    4 ++--
 5 files changed, 12 insertions(+), 16 deletions(-)

diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module
index 7c96247..1663343 100644
--- a/core/modules/comment/comment.module
+++ b/core/modules/comment/comment.module
@@ -994,8 +994,7 @@ function comment_view(Comment $comment, Node $node, $view_mode = 'full', $langco
   }
 
   // Allow modules to modify the structured comment.
-  $type = 'comment';
-  drupal_alter(array('comment_view', 'entity_view'), $build, $type);
+  drupal_alter(array('comment_view', 'entity_view'), $build, $comment);
 
   return $build;
 }
@@ -1044,7 +1043,7 @@ function comment_build_content(Comment $comment, Node $node, $view_mode = 'full'
 
   // Allow modules to make their own additions to the comment.
   module_invoke_all('comment_view', $comment, $view_mode, $langcode);
-  module_invoke_all('entity_view', $comment, 'comment', $view_mode, $langcode);
+  module_invoke_all('entity_view', $comment, $view_mode, $langcode);
 }
 
 /**
diff --git a/core/modules/entity/entity.api.php b/core/modules/entity/entity.api.php
index 37263a6..c0821a7 100644
--- a/core/modules/entity/entity.api.php
+++ b/core/modules/entity/entity.api.php
@@ -371,10 +371,8 @@ function hook_entity_query_alter($query) {
 /**
  * Act on entities being assembled before rendering.
  *
- * @param $entity
+ * @param Drupal\entity\EntityInterface $entity
  *   The entity object.
- * @param $type
- *   The type of entity being rendered (i.e. node, user, comment).
  * @param $view_mode
  *   The view mode the entity is rendered in.
  * @param $langcode
@@ -389,7 +387,7 @@ function hook_entity_query_alter($query) {
  * @see hook_node_view()
  * @see hook_user_view()
  */
-function hook_entity_view($entity, $type, $view_mode, $langcode) {
+function hook_entity_view(Drupal\entity\EntityInterface $entity, $view_mode, $langcode) {
   $entity->content['my_additional_field'] = array(
     '#markup' => $additional_field,
     '#weight' => 10,
@@ -412,8 +410,8 @@ function hook_entity_view($entity, $type, $view_mode, $langcode) {
  *
  * @param $build
  *   A renderable array representing the entity content.
- * @param $type
- *   The type of entity being rendered (i.e. node, user, comment).
+ * @param Drupal\entity\EntityInterface $entity
+ *   The entity object being rendered.
  *
  * @see hook_entity_view()
  * @see hook_comment_view_alter()
@@ -421,7 +419,7 @@ function hook_entity_view($entity, $type, $view_mode, $langcode) {
  * @see hook_taxonomy_term_view_alter()
  * @see hook_user_view_alter()
  */
-function hook_entity_view_alter(&$build, $type) {
+function hook_entity_view_alter(&$build, Drupal\entity\EntityInterface $entity) {
   if ($build['#view_mode'] == 'full' && isset($build['an_additional_field'])) {
     // Change its weight.
     $build['an_additional_field']['#weight'] = -10;
diff --git a/core/modules/node/node.module b/core/modules/node/node.module
index 171a74b..35c3a6f 100644
--- a/core/modules/node/node.module
+++ b/core/modules/node/node.module
@@ -1158,8 +1158,7 @@ function node_view(Node $node, $view_mode = 'full', $langcode = NULL) {
   }
 
   // Allow modules to modify the structured node.
-  $type = 'node';
-  drupal_alter(array('node_view', 'entity_view'), $build, $type);
+  drupal_alter(array('node_view', 'entity_view'), $build, $node);
 
   return $build;
 }
@@ -1239,7 +1238,7 @@ function node_build_content(Node $node, $view_mode = 'full', $langcode = NULL) {
 
   // Allow modules to make their own additions to the node.
   module_invoke_all('node_view', $node, $view_mode, $langcode);
-  module_invoke_all('entity_view', $node, 'node', $view_mode, $langcode);
+  module_invoke_all('entity_view', $node, $view_mode, $langcode);
 }
 
 /**
diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module
index 30eba40..55a58e0 100644
--- a/core/modules/taxonomy/taxonomy.module
+++ b/core/modules/taxonomy/taxonomy.module
@@ -613,7 +613,7 @@ function taxonomy_term_view(Term $term, $view_mode = 'full', $langcode = NULL) {
 
   // Allow modules to modify the structured term.
   $type = 'taxonomy_term';
-  drupal_alter(array('taxonomy_term_view', 'entity_view'), $build, $type);
+  drupal_alter(array('taxonomy_term_view', 'entity_view'), $build, $term);
 
   return $build;
 }
diff --git a/core/modules/user/user.module b/core/modules/user/user.module
index 6a04d7c..b344554 100644
--- a/core/modules/user/user.module
+++ b/core/modules/user/user.module
@@ -2386,7 +2386,7 @@ function user_view($account, $view_mode = 'full', $langcode = NULL) {
 
   // Allow modules to modify the structured user.
   $type = 'user';
-  drupal_alter(array('user_view', 'entity_view'), $build, $type);
+  drupal_alter(array('user_view', 'entity_view'), $build, $account);
 
   return $build;
 }
@@ -2417,7 +2417,7 @@ function user_build_content($account, $view_mode = 'full', $langcode = NULL) {
 
   // Populate $account->content with a render() array.
   module_invoke_all('user_view', $account, $view_mode, $langcode);
-  module_invoke_all('entity_view', $account, 'user', $view_mode, $langcode);
+  module_invoke_all('entity_view', $account, $view_mode, $langcode);
 }
 
 /**
-- 
1.7.4.msysgit.0

