diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index a714419..a43b2d1 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -1022,6 +1022,14 @@ function comment_build_content(Comment $comment, $node, $view_mode = 'full', $la // Remove previously built content, if exists. $comment->content = array(); + // Allow modules to change the view mode. + $context = array( + 'entity_type' => 'comment', + 'entity' => $comment, + 'langcode' => $langcode, + ); + drupal_alter('entity_view_mode', $view_mode, $context); + // Build fields content. field_attach_prepare_view('comment', array($comment->cid => $comment), $view_mode, $langcode); entity_prepare_view('comment', array($comment->cid => $comment), $langcode); diff --git a/core/modules/entity/entity.api.php b/core/modules/entity/entity.api.php index e983778..f7fe4a9 100644 --- a/core/modules/entity/entity.api.php +++ b/core/modules/entity/entity.api.php @@ -444,3 +444,15 @@ function hook_entity_prepare_view($entities, $type) { } } } + +/** + * Change the view mode of an entity that is being displayed. + * + * @param string $view_mode + * The view_mode that is to be used to display the entity. + * @param array $context + * An array with the keys entity_type, entity and langcode. + */ +function hook_entity_view_mode_alter(&$view_mode, array $context) { + +} \ No newline at end of file diff --git a/core/modules/node/node.module b/core/modules/node/node.module index a59a5c7..9da9f5d 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -1406,6 +1406,14 @@ function node_build_content($node, $view_mode = 'full', $langcode = NULL) { // Remove previously built content, if exists. $node->content = array(); + // Allow modules to change the view mode. + $context = array( + 'entity_type' => 'node', + 'entity' => $node, + 'langcode' => $langcode, + ); + drupal_alter('entity_view_mode', $view_mode, $context); + // The 'view' hook can be implemented to overwrite the default function // to display nodes. if (node_hook($node, 'view')) { diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index e82edfc..a7d5974 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -583,6 +583,14 @@ function taxonomy_term_view(TaxonomyTerm $term, $view_mode = 'full', $langcode = $langcode = $GLOBALS['language_content']->langcode; } + // Allow modules to change the view mode. + $context = array( + 'entity_type' => 'taxonomy_term', + 'entity' => $term, + 'langcode' => $langcode, + ); + drupal_alter('entity_view_mode', $view_mode, $context); + field_attach_prepare_view('taxonomy_term', array($term->tid => $term), $view_mode, $langcode); entity_prepare_view('taxonomy_term', array($term->tid => $term), $langcode); diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 3b1d9cb..db50054 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -2560,6 +2560,14 @@ function user_build_content($account, $view_mode = 'full', $langcode = NULL) { // Remove previously built content, if exists. $account->content = array(); + // Allow modules to change the view mode. + $context = array( + 'entity_type' => 'user', + 'entity' => $account, + 'langcode' => $langcode, + ); + drupal_alter('entity_view_mode', $view_mode, $context); + // Build fields content. field_attach_prepare_view('user', array($account->uid => $account), $view_mode, $langcode); entity_prepare_view('user', array($account->uid => $account), $langcode);