From 8ec40cc27a72e3dec43d80432a3250af7c03aed3 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sun, 3 Oct 2010 01:15:34 +0000 Subject: - Patch #922824 by plach: no way to specify the language to view entities in. --- modules/node/node.module | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'modules/node/node.module') diff --git a/modules/node/node.module b/modules/node/node.module index a572d494b..990a93dd2 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -1208,13 +1208,20 @@ function node_revision_delete($revision_id) { * A node object. * @param $view_mode * View mode, e.g. 'full', 'teaser'... + * @param $langcode + * (optional) A language code to use for rendering. Defaults to the global + * content language of the current request. * * @return * An array as expected by drupal_render(). */ -function node_view($node, $view_mode = 'full') { +function node_view($node, $view_mode = 'full', $langcode = NULL) { + if (!isset($langcode)) { + $langcode = $GLOBALS['language_content']->language; + } + // Populate $node->content with a render() array. - node_build_content($node, $view_mode); + node_build_content($node, $view_mode, $langcode); $build = $node->content; // We don't need duplicate rendering info in node->content. @@ -1224,7 +1231,9 @@ function node_view($node, $view_mode = 'full') { '#theme' => 'node', '#node' => $node, '#view_mode' => $view_mode, + '#language' => $langcode, ); + // Add contextual links for this node, except when the node is already being // displayed on its own page. Modules may alter this behavior (for example, // to restrict contextual links to certain view modes) by implementing @@ -1263,8 +1272,15 @@ function node_view($node, $view_mode = 'full') { * A node object. * @param $view_mode * View mode, e.g. 'full', 'teaser'... + * @param $langcode + * (optional) A language code to use for rendering. Defaults to the global + * content language of the current request. */ -function node_build_content($node, $view_mode = 'full') { +function node_build_content($node, $view_mode = 'full', $langcode = NULL) { + if (!isset($langcode)) { + $langcode = $GLOBALS['language_content']->language; + } + // Remove previously built content, if exists. $node->content = array(); @@ -1280,7 +1296,7 @@ function node_build_content($node, $view_mode = 'full') { // twice. field_attach_prepare_view('node', array($node->nid => $node), $view_mode); entity_prepare_view('node', array($node->nid => $node)); - $node->content += field_attach_view('node', $node, $view_mode); + $node->content += field_attach_view('node', $node, $view_mode, $langcode); // Always display a read more link on teasers because we have no way // to know when a teaser view is different than a full view. @@ -1299,7 +1315,7 @@ function node_build_content($node, $view_mode = 'full') { ); // Allow modules to make their own additions to the node. - module_invoke_all('node_view', $node, $view_mode); + module_invoke_all('node_view', $node, $view_mode, $langcode); } /** @@ -2434,15 +2450,19 @@ function node_feed($nids = FALSE, $channel = array()) { * View mode, e.g. 'full', 'teaser'... * @param $weight * An integer representing the weight of the first node in the list. + * @param $langcode + * (optional) A language code to use for rendering. Defaults to the global + * content language of the current request. + * * @return * An array in the format expected by drupal_render(). */ -function node_view_multiple($nodes, $view_mode = 'teaser', $weight = 0) { +function node_view_multiple($nodes, $view_mode = 'teaser', $weight = 0, $langcode = NULL) { field_attach_prepare_view('node', $nodes, $view_mode); entity_prepare_view('node', $nodes); $build = array(); foreach ($nodes as $node) { - $build['nodes'][$node->nid] = node_view($node, $view_mode); + $build['nodes'][$node->nid] = node_view($node, $view_mode, $langcode); $build['nodes'][$node->nid]['#weight'] = $weight; $weight++; } -- cgit v1.2.3