summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rothstein <drothstein@gmail.com>2012-11-06 01:59:01 -0500
committerDavid Rothstein <drothstein@gmail.com>2012-11-06 01:59:01 -0500
commit6e344fd49cdaf55a21f1ff16bb312dcc897fbb78 (patch)
tree6791c741a95e9ef9cc7acb03cb85d9403668fc1a
parent6b11350d32b753a45f4814325bdcd8aafd163050 (diff)
downloadbrdo-6e344fd49cdaf55a21f1ff16bb312dcc897fbb78.tar.gz
brdo-6e344fd49cdaf55a21f1ff16bb312dcc897fbb78.tar.bz2
Issue #1154382 followup by plach: Fixed several issues with the newly-added hook_entity_view_mode_alter().
-rw-r--r--modules/comment/comment.module4
-rw-r--r--modules/node/node.module4
-rw-r--r--modules/node/node.test4
-rw-r--r--modules/taxonomy/taxonomy.module20
-rw-r--r--modules/user/user.module4
5 files changed, 28 insertions, 8 deletions
diff --git a/modules/comment/comment.module b/modules/comment/comment.module
index 05bc7aa2b..4241538a0 100644
--- a/modules/comment/comment.module
+++ b/modules/comment/comment.module
@@ -1021,6 +1021,10 @@ function comment_build_content($comment, $node, $view_mode = 'full', $langcode =
// 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);
+
+ // Make sure the current view mode is stored if no module has already
+ // populated the related key.
+ $comment->content += array('#view_mode' => $view_mode);
}
/**
diff --git a/modules/node/node.module b/modules/node/node.module
index f181b52bb..d86c74d2d 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -1393,6 +1393,10 @@ function node_build_content($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);
+
+ // Make sure the current view mode is stored if no module has already
+ // populated the related key.
+ $node->content += array('#view_mode' => $view_mode);
}
/**
diff --git a/modules/node/node.test b/modules/node/node.test
index 9ef4c2586..34ffb05cb 100644
--- a/modules/node/node.test
+++ b/modules/node/node.test
@@ -2644,5 +2644,9 @@ class NodeEntityViewModeAlterTest extends NodeWebTestCase {
$this->assertText('Extra data that should appear only in the teaser for the node.', 'Teaser text present');
// Make sure body text is not present.
$this->assertNoText('Data that should appear only in the body for the node.', 'Body text not present');
+
+ // Test that the correct build mode has been set.
+ $build = node_view($node);
+ $this->assertEqual($build['#view_mode'], 'teaser', 'The view mode has correctly been set to teaser.');
}
}
diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module
index dc3cf44bc..905923dbf 100644
--- a/modules/taxonomy/taxonomy.module
+++ b/modules/taxonomy/taxonomy.module
@@ -811,6 +811,14 @@ function taxonomy_term_build_content($term, $view_mode = 'full', $langcode = NUL
// Remove previously built content, if exists.
$term->content = array();
+ // 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);
+
// Try to add in the core taxonomy pieces like description and nodes.
$type = 'taxonomy_term';
$entity_ids = entity_extract_ids($type, $term);
@@ -836,6 +844,10 @@ function taxonomy_term_build_content($term, $view_mode = 'full', $langcode = NUL
// Allow modules to make their own additions to the taxonomy term.
module_invoke_all('taxonomy_term_view', $term, $view_mode, $langcode);
module_invoke_all('entity_view', $term, 'taxonomy_term', $view_mode, $langcode);
+
+ // Make sure the current view mode is stored if no module has already
+ // populated the related key.
+ $term->content += array('#view_mode' => $view_mode);
}
/**
@@ -857,14 +869,6 @@ function taxonomy_term_view($term, $view_mode = 'full', $langcode = NULL) {
$langcode = $GLOBALS['language_content']->language;
}
- // 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);
-
// Populate $node->content with a render() array.
taxonomy_term_build_content($term, $view_mode, $langcode);
$build = $term->content;
diff --git a/modules/user/user.module b/modules/user/user.module
index 19ec99c6b..2c02f8ce9 100644
--- a/modules/user/user.module
+++ b/modules/user/user.module
@@ -2589,6 +2589,10 @@ 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);
+
+ // Make sure the current view mode is stored if no module has already
+ // populated the related key.
+ $account->content += array('#view_mode' => $view_mode);
}
/**