--- 1968348-hook_entity_view_mode_alter-major-errors-12.diff 2013-04-26 13:28:58.000000000 +0200 +++ 1968348-hook_entity_view_mode_alter-major-errors-18.diff 2013-06-24 12:31:55.140843183 +0200 @@ -1,8 +1,8 @@ diff --git a/includes/common.inc b/includes/common.inc -index 31923f2..0ce685e 100644 +index 9283766..d4a5429 100644 --- a/includes/common.inc +++ b/includes/common.inc -@@ -7833,6 +7833,54 @@ function entity_prepare_view($entity_type, $entities, $langcode = NULL) { +@@ -7860,6 +7860,56 @@ function entity_prepare_view($entity_type, $entities, $langcode = NULL) { } /** @@ -18,6 +18,8 @@ + * The type of entity, i.e. 'node', 'user'. + * @param $entities + * The entity objects which are being prepared for view, keyed by object ID. ++ * @param $view_mode ++ * The original view mode e.g. 'full', 'teaser'... + * @param $langcode + * (optional) A language code to be used for rendering. Defaults to the global + * content language of the current request. @@ -58,7 +60,7 @@ * * @param $entity_type diff --git a/modules/comment/comment.module b/modules/comment/comment.module -index a83069f..c9f1fdf 100644 +index a83069f..4702659 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -993,12 +993,7 @@ function comment_build_content($comment, $node, $view_mode = 'full', $langcode = @@ -75,22 +77,33 @@ // Build fields content. field_attach_prepare_view('comment', array($comment->cid => $comment), $view_mode, $langcode); -@@ -1108,8 +1103,11 @@ function comment_links($comment, $node) { +@@ -1108,14 +1103,18 @@ function comment_links($comment, $node) { * An array in the format expected by drupal_render(). */ function comment_view_multiple($comments, $node, $view_mode = 'full', $weight = 0, $langcode = NULL) { - field_attach_prepare_view('comment', $comments, $view_mode, $langcode); - entity_prepare_view('comment', $comments, $langcode); -+ $comments_by_view_mode = entity_view_mode_prepare('comment', $comments, $view_mode, $langcode); -+ foreach ($comments_by_view_mode as $view_mode => $comments) { -+ field_attach_prepare_view('comment', $comments, $view_mode, $langcode); -+ entity_prepare_view('comment', $comments, $langcode); ++ $build = array(); ++ $entities_by_view_mode = entity_view_mode_prepare('comment', $comments, $view_mode, $langcode); ++ foreach ($entities_by_view_mode as $entity_view_mode => $entities) { ++ field_attach_prepare_view('comment', $entities, $entity_view_mode, $langcode); ++ entity_prepare_view('comment', $entities, $langcode); ++ ++ foreach ($entities as $entity) { ++ $build[$entity->cid] = comment_view($entity, $node, $entity_view_mode, $langcode); ++ } + } - $build = array( - '#sorted' => TRUE, +- $build = array( +- '#sorted' => TRUE, +- ); + foreach ($comments as $comment) { +- $build[$comment->cid] = comment_view($comment, $node, $view_mode, $langcode); + $build[$comment->cid]['#weight'] = $weight; + $weight++; + } diff --git a/modules/node/node.module b/modules/node/node.module -index f20c229..af3ed56 100644 +index f20c229..d32335c 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -1399,12 +1399,7 @@ function node_build_content($node, $view_mode = 'full', $langcode = NULL) { @@ -107,26 +120,37 @@ // The 'view' hook can be implemented to overwrite the default function // to display nodes. -@@ -2663,8 +2658,12 @@ function node_feed($nids = FALSE, $channel = array()) { +@@ -2663,15 +2658,21 @@ function node_feed($nids = FALSE, $channel = array()) { * An array in the format expected by drupal_render(). */ function node_view_multiple($nodes, $view_mode = 'teaser', $weight = 0, $langcode = NULL) { - field_attach_prepare_view('node', $nodes, $view_mode, $langcode); - entity_prepare_view('node', $nodes, $langcode); -+ $nodes_by_view_mode = entity_view_mode_prepare('node', $nodes, $view_mode, $langcode); -+ foreach ($nodes_by_view_mode as $view_mode => $nodes) { -+ field_attach_prepare_view('node', $nodes, $view_mode, $langcode); -+ entity_prepare_view('node', $nodes, $langcode); + $build = array(); ++ $entities_by_view_mode = entity_view_mode_prepare('node', $nodes, $view_mode, $langcode); ++ foreach ($entities_by_view_mode as $entity_view_mode => $entitys) { ++ field_attach_prepare_view('node', $entitys, $entity_view_mode, $langcode); ++ entity_prepare_view('node', $entitys, $langcode); ++ ++ foreach ($entitys as $entity) { ++ $build['nodes'][$entity->nid] = node_view($entity, $entity_view_mode, $langcode); ++ } + } + - $build = array(); foreach ($nodes as $node) { - $build['nodes'][$node->nid] = node_view($node, $view_mode, $langcode); +- $build['nodes'][$node->nid] = node_view($node, $view_mode, $langcode); + $build['nodes'][$node->nid]['#weight'] = $weight; + $weight++; + } +- $build['nodes']['#sorted'] = TRUE; + return $build; + } + diff --git a/modules/node/node.test b/modules/node/node.test -index 0256fec..feff883 100644 +index b1d78fa..0009f8a 100644 --- a/modules/node/node.test +++ b/modules/node/node.test -@@ -2678,8 +2678,8 @@ class NodeEntityViewModeAlterTest extends NodeWebTestCase { +@@ -2735,8 +2735,8 @@ class NodeEntityViewModeAlterTest extends NodeWebTestCase { $edit = array(); $langcode = LANGUAGE_NONE; $edit["title"] = $this->randomName(8); @@ -137,37 +161,20 @@ $this->drupalPost('node/add/page', $edit, t('Save')); $node = $this->drupalGetNodeByTitle($edit["title"]); -@@ -2698,3 +2698,60 @@ class NodeEntityViewModeAlterTest extends NodeWebTestCase { +@@ -2754,4 +2754,43 @@ class NodeEntityViewModeAlterTest extends NodeWebTestCase { + $build = node_view($node); $this->assertEqual($build['#view_mode'], 'teaser', 'The view mode has correctly been set to teaser.'); } - } -+ -+/** -+ * Tests changing view mode for nodes when teaser display shows a field which is missing on the default display. -+ */ -+class NodeEntityViewModeAlterMinimalDefaultDisplayTest extends NodeWebTestCase { -+ -+ public static function getInfo() { -+ return array( -+ 'name' => 'Node entity view mode minimal default display', -+ 'description' => 'Test changing view mode when teaser display shows a field which is missing on the default display.', -+ 'group' => 'Node' -+ ); -+ } -+ -+ function setUp() { -+ parent::setUp(array('node_test')); + ++ /** ++ * Tests fields that were previously hidden when the view mode is changed. ++ */ ++ function testNodeViewModeChangeHiddenField() { + // Hide the tags field on the default display -+ $instance = field_read_instance('node', 'field_tags', 'article'); ++ $instance = field_info_instance('node', 'field_tags', 'article'); + $instance['display']['default']['type'] = 'hidden'; + field_update_instance($instance); -+ } + -+ /** -+ * Create a "Article" node and verify its consistency in the database. -+ */ -+ function testNodeViewModeChange() { + $web_user = $this->drupalCreateUser(array('create article content', 'edit own article content')); + $this->drupalLogin($web_user); + @@ -197,26 +204,38 @@ + $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 7ad28e9..1045c2f 100644 +index 7ad28e9..3260c71 100644 --- a/modules/taxonomy/taxonomy.module +++ b/modules/taxonomy/taxonomy.module -@@ -771,8 +771,11 @@ function taxonomy_term_show($term) { +@@ -771,15 +771,21 @@ function taxonomy_term_show($term) { * An array in the format expected by drupal_render(). */ function taxonomy_term_view_multiple($terms, $view_mode = 'teaser', $weight = 0, $langcode = NULL) { - field_attach_prepare_view('taxonomy_term', $terms, $view_mode, $langcode); - entity_prepare_view('taxonomy_term', $terms, $langcode); -+ $terms_by_view_mode = entity_view_mode_prepare('taxonomy_term', $terms, $view_mode, $langcode); -+ foreach ($terms_by_view_mode as $view_mode => $terms) { -+ field_attach_prepare_view('taxonomy_term', $terms, $view_mode, $langcode); -+ entity_prepare_view('taxonomy_term', $terms, $langcode); -+ } $build = array(); ++ $entities_by_view_mode = entity_view_mode_prepare('taxonomy_term', $terms, $view_mode, $langcode); ++ foreach ($entities_by_view_mode as $entity_view_mode => $entities) { ++ field_attach_prepare_view('taxonomy_term', $entities, $entity_view_mode, $langcode); ++ entity_prepare_view('taxonomy_term', $entities, $langcode); ++ ++ foreach ($entities as $entity) { ++ $build['taxonomy_terms'][$entity->tid] = taxonomy_term_view($entity, $entity_view_mode, $langcode); ++ } ++ } ++ foreach ($terms as $term) { - $build['taxonomy_terms'][$term->tid] = taxonomy_term_view($term, $view_mode, $langcode); -@@ -812,12 +815,7 @@ function taxonomy_term_build_content($term, $view_mode = 'full', $langcode = NUL +- $build['taxonomy_terms'][$term->tid] = taxonomy_term_view($term, $view_mode, $langcode); + $build['taxonomy_terms'][$term->tid]['#weight'] = $weight; + $weight++; + } +- $build['taxonomy_terms']['#sorted'] = TRUE; + return $build; + } + +@@ -812,12 +818,7 @@ function taxonomy_term_build_content($term, $view_mode = 'full', $langcode = NUL $term->content = array(); // Allow modules to change the view mode. @@ -231,10 +250,10 @@ // Add the term description if the term has one and it is visible. $type = 'taxonomy_term'; diff --git a/modules/user/user.module b/modules/user/user.module -index e8bcbc5..c801818 100644 +index 06233fc..308c3b7 100644 --- a/modules/user/user.module +++ b/modules/user/user.module -@@ -2596,12 +2596,7 @@ function user_build_content($account, $view_mode = 'full', $langcode = NULL) { +@@ -2604,12 +2604,7 @@ function user_build_content($account, $view_mode = 'full', $langcode = NULL) { $account->content = array(); // Allow modules to change the view mode.