summaryrefslogtreecommitdiff
path: root/modules/node
diff options
context:
space:
mode:
authorwebchick <webchick@24967.no-reply.drupal.org>2012-09-30 20:37:55 -0400
committerwebchick <webchick@24967.no-reply.drupal.org>2012-09-30 20:37:55 -0400
commit13f16ae3423087824118e1e5c07f88396a85c8f7 (patch)
tree7a9678d7256d44fdcd4d5580a548ffca98aa7459 /modules/node
parentc3cba0532ba45692af5378d1b89e745ea0df3701 (diff)
downloadbrdo-13f16ae3423087824118e1e5c07f88396a85c8f7.tar.gz
brdo-13f16ae3423087824118e1e5c07f88396a85c8f7.tar.bz2
Issue #1154382 by Berdir, barraponto, acouch, swentel, LoMo, DamienMcKenna, chx: Fixed View mode no longer can be changed.
Diffstat (limited to 'modules/node')
-rw-r--r--modules/node/node.module8
-rw-r--r--modules/node/node.test45
-rw-r--r--modules/node/tests/node_test.module10
3 files changed, 63 insertions, 0 deletions
diff --git a/modules/node/node.module b/modules/node/node.module
index d3d1c85b1..f181b52bb 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -1345,6 +1345,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/modules/node/node.test b/modules/node/node.test
index 253e7da84..9ef4c2586 100644
--- a/modules/node/node.test
+++ b/modules/node/node.test
@@ -2601,3 +2601,48 @@ class NodeAccessFieldTestCase extends NodeWebTestCase {
$this->assertRaw($default, 'The updated default value is displayed when creating a new node.');
}
}
+
+/**
+ * Tests changing view modes for nodes.
+ */
+class NodeEntityViewModeAlterTest extends NodeWebTestCase {
+
+ public static function getInfo() {
+ return array(
+ 'name' => 'Node entity view mode',
+ 'description' => 'Test changing view mode.',
+ 'group' => 'Node'
+ );
+ }
+
+ function setUp() {
+ parent::setUp(array('node_test'));
+ }
+
+ /**
+ * Create a "Basic page" node and verify its consistency in the database.
+ */
+ function testNodeViewModeChange() {
+ $web_user = $this->drupalCreateUser(array('create page content', 'edit own page content'));
+ $this->drupalLogin($web_user);
+
+ // Create a node.
+ $edit = array();
+ $langcode = LANGUAGE_NONE;
+ $edit["title"] = $this->randomName(8);
+ $edit["body[$langcode][0][value]"] = t('Data that should appear only in the body for the node.');
+ $edit["body[$langcode][0][summary]"] = t('Extra data that should appear only in the teaser for the node.');
+ $this->drupalPost('node/add/page', $edit, t('Save'));
+
+ $node = $this->drupalGetNodeByTitle($edit["title"]);
+
+ // Set the flag to alter the view mode and view the node.
+ variable_set('node_test_change_view_mode', 'teaser');
+ $this->drupalGet('node/' . $node->nid);
+
+ // Check that teaser mode is viewed.
+ $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');
+ }
+}
diff --git a/modules/node/tests/node_test.module b/modules/node/tests/node_test.module
index b0ebc149a..a52c1fad0 100644
--- a/modules/node/tests/node_test.module
+++ b/modules/node/tests/node_test.module
@@ -149,3 +149,13 @@ function node_test_node_update($node) {
}
}
}
+
+/**
+ * Implements hook_entity_view_mode_alter().
+ */
+function node_test_entity_view_mode_alter(&$view_mode, $context) {
+ // Only alter the view mode if we are on the test callback.
+ if ($change_view_mode = variable_get('node_test_change_view_mode', '')) {
+ $view_mode = $change_view_mode;
+ }
+}