summaryrefslogtreecommitdiff
path: root/modules/node
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2010-10-03 01:15:34 +0000
committerDries Buytaert <dries@buytaert.net>2010-10-03 01:15:34 +0000
commit8ec40cc27a72e3dec43d80432a3250af7c03aed3 (patch)
treefcc37f6506cc2e8c511399584a899c40c70e0772 /modules/node
parent69e9e3e3a2c2d52a149914565fa451ed967280e1 (diff)
downloadbrdo-8ec40cc27a72e3dec43d80432a3250af7c03aed3.tar.gz
brdo-8ec40cc27a72e3dec43d80432a3250af7c03aed3.tar.bz2
- Patch #922824 by plach: no way to specify the language to view entities in.
Diffstat (limited to 'modules/node')
-rw-r--r--modules/node/node.api.php4
-rw-r--r--modules/node/node.module34
2 files changed, 30 insertions, 8 deletions
diff --git a/modules/node/node.api.php b/modules/node/node.api.php
index 7d4f3996f..c1b84cbbc 100644
--- a/modules/node/node.api.php
+++ b/modules/node/node.api.php
@@ -756,10 +756,12 @@ function hook_node_submit($node, $form, &$form_state) {
* The node that is being assembled for rendering.
* @param $view_mode
* The $view_mode parameter from node_view().
+ * @param $langcode
+ * The language code used for rendering.
*
* @ingroup node_api_hooks
*/
-function hook_node_view($node, $view_mode) {
+function hook_node_view($node, $view_mode, $langcode) {
$node->content['my_additional_field'] = array(
'#markup' => $additional_field,
'#weight' => 10,
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++;
}