Commit 8ec40cc2 authored by Dries's avatar Dries
Browse files

- Patch #922824 by plach: no way to specify the language to view entities in.

parent 69e9e3e3
...@@ -64,10 +64,12 @@ function hook_comment_load($comments) { ...@@ -64,10 +64,12 @@ function hook_comment_load($comments) {
* *
* @param $comment * @param $comment
* Passes in the comment the action is being performed on. * Passes in the comment the action is being performed on.
* @return * @param $view_mode
* Nothing. * View mode, e.g. 'full', 'teaser'...
* @param $langcode
* The language code used for rendering.
*/ */
function hook_comment_view($comment) { function hook_comment_view($comment, $view_mode, $langcode) {
// how old is the comment // how old is the comment
$comment->time_ago = time() - $comment->changed; $comment->time_ago = time() - $comment->changed;
} }
......
...@@ -887,13 +887,20 @@ function comment_prepare_thread(&$comments) { ...@@ -887,13 +887,20 @@ function comment_prepare_thread(&$comments) {
* The node the comment is attached to. * The node the comment is attached to.
* @param $view_mode * @param $view_mode
* View mode, e.g. 'full', 'teaser'... * 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 * @return
* An array as expected by drupal_render(). * An array as expected by drupal_render().
*/ */
function comment_view($comment, $node, $view_mode = 'full') { function comment_view($comment, $node, $view_mode = 'full', $langcode = NULL) {
if (!isset($langcode)) {
$langcode = $GLOBALS['language_content']->language;
}
// Populate $comment->content with a render() array. // Populate $comment->content with a render() array.
comment_build_content($comment, $node, $view_mode); comment_build_content($comment, $node, $view_mode, $langcode);
$build = $comment->content; $build = $comment->content;
// We don't need duplicate rendering info in comment->content. // We don't need duplicate rendering info in comment->content.
...@@ -904,6 +911,7 @@ function comment_view($comment, $node, $view_mode = 'full') { ...@@ -904,6 +911,7 @@ function comment_view($comment, $node, $view_mode = 'full') {
'#comment' => $comment, '#comment' => $comment,
'#node' => $node, '#node' => $node,
'#view_mode' => $view_mode, '#view_mode' => $view_mode,
'#language' => $langcode,
); );
if (empty($comment->in_preview)) { if (empty($comment->in_preview)) {
...@@ -948,15 +956,22 @@ function comment_view($comment, $node, $view_mode = 'full') { ...@@ -948,15 +956,22 @@ function comment_view($comment, $node, $view_mode = 'full') {
* The node the comment is attached to. * The node the comment is attached to.
* @param $view_mode * @param $view_mode
* View mode, e.g. 'full', 'teaser'... * 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 comment_build_content($comment, $node, $view_mode = 'full') { function comment_build_content($comment, $node, $view_mode = 'full', $langcode = NULL) {
if (!isset($langcode)) {
$langcode = $GLOBALS['language_content']->language;
}
// Remove previously built content, if exists. // Remove previously built content, if exists.
$comment->content = array(); $comment->content = array();
// Build fields content. // Build fields content.
field_attach_prepare_view('comment', array($comment->cid => $comment), $view_mode); field_attach_prepare_view('comment', array($comment->cid => $comment), $view_mode);
entity_prepare_view('comment', array($comment->cid => $comment)); entity_prepare_view('comment', array($comment->cid => $comment));
$comment->content += field_attach_view('comment', $comment, $view_mode); $comment->content += field_attach_view('comment', $comment, $view_mode, $langcode);
if (empty($comment->in_preview)) { if (empty($comment->in_preview)) {
$comment->content['links']['comment'] = array( $comment->content['links']['comment'] = array(
...@@ -967,7 +982,7 @@ function comment_build_content($comment, $node, $view_mode = 'full') { ...@@ -967,7 +982,7 @@ function comment_build_content($comment, $node, $view_mode = 'full') {
} }
// Allow modules to make their own additions to the comment. // Allow modules to make their own additions to the comment.
module_invoke_all('comment_view', $comment, $view_mode); module_invoke_all('comment_view', $comment, $view_mode, $langcode);
} }
/** /**
...@@ -1043,10 +1058,14 @@ function comment_links($comment, $node) { ...@@ -1043,10 +1058,14 @@ function comment_links($comment, $node) {
* View mode, e.g. 'full', 'teaser'... * View mode, e.g. 'full', 'teaser'...
* @param $weight * @param $weight
* An integer representing the weight of the first comment in the list. * An integer representing the weight of the first comment in the list.
* @param $langcode
* A string indicating the language field values are to be shown in. If no
* language is provided the current content language is used.
*
* @return * @return
* An array in the format expected by drupal_render(). * An array in the format expected by drupal_render().
*/ */
function comment_view_multiple($comments, $node, $view_mode = 'full', $weight = 0) { function comment_view_multiple($comments, $node, $view_mode = 'full', $weight = 0, $langcode = NULL) {
field_attach_prepare_view('comment', $comments, $view_mode); field_attach_prepare_view('comment', $comments, $view_mode);
entity_prepare_view('comment', $comments); entity_prepare_view('comment', $comments);
...@@ -1054,7 +1073,7 @@ function comment_view_multiple($comments, $node, $view_mode = 'full', $weight = ...@@ -1054,7 +1073,7 @@ function comment_view_multiple($comments, $node, $view_mode = 'full', $weight =
'#sorted' => TRUE, '#sorted' => TRUE,
); );
foreach ($comments as $comment) { foreach ($comments as $comment) {
$build[$comment->cid] = comment_view($comment, $node, $view_mode); $build[$comment->cid] = comment_view($comment, $node, $view_mode, $langcode);
$build[$comment->cid]['#weight'] = $weight; $build[$comment->cid]['#weight'] = $weight;
$weight++; $weight++;
} }
......
...@@ -1236,6 +1236,7 @@ function hook_field_attach_purge($entity_type, $entity, $field, $instance) { ...@@ -1236,6 +1236,7 @@ function hook_field_attach_purge($entity_type, $entity, $field, $instance) {
* - entity_type: The type of $entity; for example, 'node' or 'user'. * - entity_type: The type of $entity; for example, 'node' or 'user'.
* - entity: The entity with fields to render. * - entity: The entity with fields to render.
* - view_mode: View mode, for example, 'full' or 'teaser'. * - view_mode: View mode, for example, 'full' or 'teaser'.
* - language: The language code used for rendering.
*/ */
function hook_field_attach_view_alter(&$output, $context) { function hook_field_attach_view_alter(&$output, $context) {
// Append RDF term mappings on displayed taxonomy links. // Append RDF term mappings on displayed taxonomy links.
......
...@@ -1146,6 +1146,7 @@ function field_attach_view($entity_type, $entity, $view_mode, $langcode = NULL) ...@@ -1146,6 +1146,7 @@ function field_attach_view($entity_type, $entity, $view_mode, $langcode = NULL)
'entity_type' => $entity_type, 'entity_type' => $entity_type,
'entity' => $entity, 'entity' => $entity,
'view_mode' => $view_mode, 'view_mode' => $view_mode,
'language' => $langcode,
); );
drupal_alter('field_attach_view', $output, $context); drupal_alter('field_attach_view', $output, $context);
......
...@@ -756,10 +756,12 @@ function hook_node_submit($node, $form, &$form_state) { ...@@ -756,10 +756,12 @@ function hook_node_submit($node, $form, &$form_state) {
* The node that is being assembled for rendering. * The node that is being assembled for rendering.
* @param $view_mode * @param $view_mode
* The $view_mode parameter from node_view(). * The $view_mode parameter from node_view().
* @param $langcode
* The language code used for rendering.
* *
* @ingroup node_api_hooks * @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( $node->content['my_additional_field'] = array(
'#markup' => $additional_field, '#markup' => $additional_field,
'#weight' => 10, '#weight' => 10,
......
...@@ -1208,13 +1208,20 @@ function node_revision_delete($revision_id) { ...@@ -1208,13 +1208,20 @@ function node_revision_delete($revision_id) {
* A node object. * A node object.
* @param $view_mode * @param $view_mode
* View mode, e.g. 'full', 'teaser'... * 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 * @return
* An array as expected by drupal_render(). * 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. // Populate $node->content with a render() array.
node_build_content($node, $view_mode); node_build_content($node, $view_mode, $langcode);
$build = $node->content; $build = $node->content;
// We don't need duplicate rendering info in node->content. // We don't need duplicate rendering info in node->content.
...@@ -1224,7 +1231,9 @@ function node_view($node, $view_mode = 'full') { ...@@ -1224,7 +1231,9 @@ function node_view($node, $view_mode = 'full') {
'#theme' => 'node', '#theme' => 'node',
'#node' => $node, '#node' => $node,
'#view_mode' => $view_mode, '#view_mode' => $view_mode,
'#language' => $langcode,
); );
// Add contextual links for this node, except when the node is already being // 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, // displayed on its own page. Modules may alter this behavior (for example,
// to restrict contextual links to certain view modes) by implementing // to restrict contextual links to certain view modes) by implementing
...@@ -1263,8 +1272,15 @@ function node_view($node, $view_mode = 'full') { ...@@ -1263,8 +1272,15 @@ function node_view($node, $view_mode = 'full') {
* A node object. * A node object.
* @param $view_mode * @param $view_mode
* View mode, e.g. 'full', 'teaser'... * 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. // Remove previously built content, if exists.
$node->content = array(); $node->content = array();
...@@ -1280,7 +1296,7 @@ function node_build_content($node, $view_mode = 'full') { ...@@ -1280,7 +1296,7 @@ function node_build_content($node, $view_mode = 'full') {
// twice. // twice.
field_attach_prepare_view('node', array($node->nid => $node), $view_mode); field_attach_prepare_view('node', array($node->nid => $node), $view_mode);
entity_prepare_view('node', array($node->nid => $node)); 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 // 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. // to know when a teaser view is different than a full view.
...@@ -1299,7 +1315,7 @@ function node_build_content($node, $view_mode = 'full') { ...@@ -1299,7 +1315,7 @@ function node_build_content($node, $view_mode = 'full') {
); );
// Allow modules to make their own additions to the node. // 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()) { ...@@ -2434,15 +2450,19 @@ function node_feed($nids = FALSE, $channel = array()) {
* View mode, e.g. 'full', 'teaser'... * View mode, e.g. 'full', 'teaser'...
* @param $weight * @param $weight
* An integer representing the weight of the first node in the list. * 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 * @return
* An array in the format expected by drupal_render(). * 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); field_attach_prepare_view('node', $nodes, $view_mode);
entity_prepare_view('node', $nodes); entity_prepare_view('node', $nodes);
$build = array(); $build = array();
foreach ($nodes as $node) { 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; $build['nodes'][$node->nid]['#weight'] = $weight;
$weight++; $weight++;
} }
......
...@@ -599,11 +599,18 @@ function taxonomy_term_delete($tid) { ...@@ -599,11 +599,18 @@ function taxonomy_term_delete($tid) {
* A term object. * A term object.
* @param $view_mode * @param $view_mode
* View mode, e.g. 'full', 'teaser'... * 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 * @return
* An array as expected by drupal_render(). * An array as expected by drupal_render().
*/ */
function taxonomy_term_view($term, $view_mode = 'full') { function taxonomy_term_view($term, $view_mode = 'full', $langcode = NULL) {
if (!isset($langcode)) {
$langcode = $GLOBALS['language_content']->language;
}
field_attach_prepare_view('taxonomy_term', array($term->tid => $term), $view_mode); field_attach_prepare_view('taxonomy_term', array($term->tid => $term), $view_mode);
entity_prepare_view('taxonomy_term', array($term->tid => $term)); entity_prepare_view('taxonomy_term', array($term->tid => $term));
...@@ -611,9 +618,10 @@ function taxonomy_term_view($term, $view_mode = 'full') { ...@@ -611,9 +618,10 @@ function taxonomy_term_view($term, $view_mode = 'full') {
'#theme' => 'taxonomy_term', '#theme' => 'taxonomy_term',
'#term' => $term, '#term' => $term,
'#view_mode' => $view_mode, '#view_mode' => $view_mode,
'#language' => $langcode,
); );
$build += field_attach_view('taxonomy_term', $term, $view_mode); $build += field_attach_view('taxonomy_term', $term, $view_mode, $langcode);
$build['description'] = array( $build['description'] = array(
'#markup' => check_markup($term->description, $term->format, '', TRUE), '#markup' => check_markup($term->description, $term->format, '', TRUE),
......
...@@ -314,8 +314,10 @@ function hook_user_logout($account) { ...@@ -314,8 +314,10 @@ function hook_user_logout($account) {
* The user object on which the operation is being performed. * The user object on which the operation is being performed.
* @param $view_mode * @param $view_mode
* View mode, e.g. 'full'. * View mode, e.g. 'full'.
* @param $langcode
* The language code used for rendering.
*/ */
function hook_user_view($account, $view_mode) { function hook_user_view($account, $view_mode, $langcode) {
if (user_access('create blog content', $account)) { if (user_access('create blog content', $account)) {
$account->content['summary']['blog'] = array( $account->content['summary']['blog'] = array(
'#type' => 'user_profile_item', '#type' => 'user_profile_item',
......
...@@ -2389,13 +2389,20 @@ function user_view_page($uid) { ...@@ -2389,13 +2389,20 @@ function user_view_page($uid) {
* A user object. * A user object.
* @param $view_mode * @param $view_mode
* View mode, e.g. 'full'. * View mode, e.g. 'full'.
* @param $langcode
* (optional) A language code to use for rendering. Defaults to the global
* content language of the current request.
* *
* @return * @return
* An array as expected by drupal_render(). * An array as expected by drupal_render().
*/ */
function user_view($account, $view_mode = 'full') { function user_view($account, $view_mode = 'full', $langcode = NULL) {
if (!isset($langcode)) {
$langcode = $GLOBALS['language_content']->language;
}
// Retrieve all profile fields and attach to $account->content. // Retrieve all profile fields and attach to $account->content.
user_build_content($account, $view_mode); user_build_content($account, $view_mode, $langcode);
$build = $account->content; $build = $account->content;
// We don't need duplicate rendering info in account->content. // We don't need duplicate rendering info in account->content.
...@@ -2405,6 +2412,7 @@ function user_view($account, $view_mode = 'full') { ...@@ -2405,6 +2412,7 @@ function user_view($account, $view_mode = 'full') {
'#theme' => 'user_profile', '#theme' => 'user_profile',
'#account' => $account, '#account' => $account,
'#view_mode' => $view_mode, '#view_mode' => $view_mode,
'#language' => $langcode,
); );
// Allow modules to modify the structured user. // Allow modules to modify the structured user.
...@@ -2420,18 +2428,25 @@ function user_view($account, $view_mode = 'full') { ...@@ -2420,18 +2428,25 @@ function user_view($account, $view_mode = 'full') {
* A user object. * A user object.
* @param $view_mode * @param $view_mode
* View mode, e.g. 'full'. * View mode, e.g. 'full'.
* @param $langcode
* (optional) A language code to use for rendering. Defaults to the global
* content language of the current request.
*/ */
function user_build_content($account, $view_mode = 'full') { function user_build_content($account, $view_mode = 'full', $langcode = NULL) {
if (!isset($langcode)) {
$langcode = $GLOBALS['language_content']->language;
}
// Remove previously built content, if exists. // Remove previously built content, if exists.
$account->content = array(); $account->content = array();
// Build fields content. // Build fields content.
field_attach_prepare_view('user', array($account->uid => $account), $view_mode); field_attach_prepare_view('user', array($account->uid => $account), $view_mode);
entity_prepare_view('user', array($account->uid => $account)); entity_prepare_view('user', array($account->uid => $account));
$account->content += field_attach_view('user', $account, $view_mode); $account->content += field_attach_view('user', $account, $view_mode, $langcode);
// Populate $account->content with a render() array. // Populate $account->content with a render() array.
module_invoke_all('user_view', $account, $view_mode); module_invoke_all('user_view', $account, $view_mode, $langcode);
} }
/** /**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment