Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
2a419f61
Commit
2a419f61
authored
May 13, 2011
by
Dries
Browse files
- Patch
#1089174
by plach: prepare view hooks do not receive the language parameter.
parent
7770f082
Changes
7
Hide whitespace changes
Inline
Side-by-side
includes/common.inc
View file @
2a419f61
...
...
@@ -7492,8 +7492,15 @@ function entity_get_controller($entity_type) {
* The type of entity, i.e. 'node', 'user'.
* @param $entities
* The entity objects which are being prepared for view, keyed by object ID.
* @param $langcode
* (optional) A language code to be used for rendering. Defaults to the global
* content language of the current request.
*/
function
entity_prepare_view
(
$entity_type
,
$entities
)
{
function
entity_prepare_view
(
$entity_type
,
$entities
,
$langcode
=
NULL
)
{
if
(
!
isset
(
$langcode
))
{
$langcode
=
$GLOBALS
[
'language_content'
]
->
language
;
}
// To ensure hooks are only run once per entity, check for an
// entity_view_prepared flag and only process items without it.
// @todo: resolve this more generally for both entity and field level hooks.
...
...
@@ -7509,7 +7516,7 @@ function entity_prepare_view($entity_type, $entities) {
}
if
(
!
empty
(
$prepare
))
{
module_invoke_all
(
'entity_prepare_view'
,
$prepare
,
$entity_type
);
module_invoke_all
(
'entity_prepare_view'
,
$prepare
,
$entity_type
,
$langcode
);
}
}
...
...
modules/comment/comment.module
View file @
2a419f61
...
...
@@ -988,8 +988,8 @@ function comment_build_content($comment, $node, $view_mode = 'full', $langcode =
$comment
->
content
=
array
();
// Build fields content.
field_attach_prepare_view
(
'comment'
,
array
(
$comment
->
cid
=>
$comment
),
$view_mode
);
entity_prepare_view
(
'comment'
,
array
(
$comment
->
cid
=>
$comment
));
field_attach_prepare_view
(
'comment'
,
array
(
$comment
->
cid
=>
$comment
),
$view_mode
,
$langcode
);
entity_prepare_view
(
'comment'
,
array
(
$comment
->
cid
=>
$comment
)
,
$langcode
);
$comment
->
content
+=
field_attach_view
(
'comment'
,
$comment
,
$view_mode
,
$langcode
);
$comment
->
content
[
'links'
]
=
array
(
...
...
@@ -1091,8 +1091,8 @@ 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
);
entity_prepare_view
(
'comment'
,
$comments
);
field_attach_prepare_view
(
'comment'
,
$comments
,
$view_mode
,
$langcode
);
entity_prepare_view
(
'comment'
,
$comments
,
$langcode
);
$build
=
array
(
'#sorted'
=>
TRUE
,
...
...
modules/field/field.attach.inc
View file @
2a419f61
...
...
@@ -257,9 +257,9 @@ function _field_invoke($op, $entity_type, $entity, &$a = NULL, &$b = NULL, $opti
* - 'deleted': If TRUE, the function will operate on deleted fields
* as well as non-deleted fields. If unset or FALSE, only
* non-deleted fields are operated on.
* - 'language': A language code or an array of language codes keyed
by field
* name. It will be used to narrow down to a single
value the available
* languages to act on.
* - 'language': A language code or an array of
arrays of
language codes keyed
*
by entity id and field
name. It will be used to narrow down to a single
*
value the available
languages to act on.
*
* @return
* An array of returned values keyed by entity id.
...
...
@@ -311,7 +311,8 @@ function _field_invoke_multiple($op, $entity_type, $entities, &$a = NULL, &$b =
// Unless a language suggestion is provided we iterate on all the
// available languages.
$available_languages
=
field_available_languages
(
$entity_type
,
$field
);
$languages
=
_field_language_suggestion
(
$available_languages
,
$options
[
'language'
],
$field_name
);
$language
=
!
empty
(
$options
[
'language'
][
$id
])
?
$options
[
'language'
][
$id
]
:
$options
[
'language'
];
$languages
=
_field_language_suggestion
(
$available_languages
,
$language
,
$field_name
);
foreach
(
$languages
as
$langcode
)
{
$grouped_items
[
$field_id
][
$langcode
][
$id
]
=
isset
(
$entity
->
{
$field_name
}[
$langcode
])
?
$entity
->
{
$field_name
}[
$langcode
]
:
array
();
}
...
...
@@ -1074,8 +1075,13 @@ function field_attach_delete_revision($entity_type, $entity) {
* An array of entities, keyed by entity id.
* @param $view_mode
* View mode, e.g. 'full', 'teaser'...
* @param $langcode
* (Optional) The language the field values are to be shown in. If no language
* is provided the current language is used.
*/
function
field_attach_prepare_view
(
$entity_type
,
$entities
,
$view_mode
)
{
function
field_attach_prepare_view
(
$entity_type
,
$entities
,
$view_mode
,
$langcode
=
NULL
)
{
$options
=
array
(
'language'
=>
array
());
// To ensure hooks are only run once per entity, only process items without
// the _field_view_prepared flag.
// @todo: resolve this more generally for both entity and field level hooks.
...
...
@@ -1085,17 +1091,22 @@ function field_attach_prepare_view($entity_type, $entities, $view_mode) {
// Add this entity to the items to be prepared.
$prepare
[
$id
]
=
$entity
;
// Determine the actual language to display for each field, given the
// languages available in the field data.
$options
[
'language'
][
$id
]
=
field_language
(
$entity_type
,
$entity
,
NULL
,
$langcode
);
// Mark this item as prepared.
$entity
->
_field_view_prepared
=
TRUE
;
}
}
$null
=
NULL
;
// First let the field types do their preparation.
_field_invoke_multiple
(
'prepare_view'
,
$entity_type
,
$prepare
);
_field_invoke_multiple
(
'prepare_view'
,
$entity_type
,
$prepare
,
$null
,
$null
,
$options
);
// Then let the formatters do their own specific massaging.
// field_default_prepare_view() takes care of dispatching to the correct
// formatters according to the display settings for the view mode.
_field_invoke_multiple_default
(
'prepare_view'
,
$entity_type
,
$prepare
,
$view_mode
);
_field_invoke_multiple_default
(
'prepare_view'
,
$entity_type
,
$prepare
,
$view_mode
,
$null
,
$options
);
}
/**
...
...
modules/node/node.module
View file @
2a419f61
...
...
@@ -1350,15 +1350,15 @@ function node_build_content($node, $view_mode = 'full', $langcode = NULL) {
// The 'view' hook can be implemented to overwrite the default function
// to display nodes.
if
(
node_hook
(
$node
,
'view'
))
{
$node
=
node_invoke
(
$node
,
'view'
,
$view_mode
);
$node
=
node_invoke
(
$node
,
'view'
,
$view_mode
,
$langcode
);
}
// Build fields content.
// In case of a multiple view, node_view_multiple() already ran the
// 'prepare_view' step. An internal flag prevents the operation from running
// twice.
field_attach_prepare_view
(
'node'
,
array
(
$node
->
nid
=>
$node
),
$view_mode
);
entity_prepare_view
(
'node'
,
array
(
$node
->
nid
=>
$node
));
field_attach_prepare_view
(
'node'
,
array
(
$node
->
nid
=>
$node
),
$view_mode
,
$langcode
);
entity_prepare_view
(
'node'
,
array
(
$node
->
nid
=>
$node
)
,
$langcode
);
$node
->
content
+=
field_attach_view
(
'node'
,
$node
,
$view_mode
,
$langcode
);
// Always display a read more link on teasers because we have no way
...
...
@@ -2517,8 +2517,8 @@ 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
);
entity_prepare_view
(
'node'
,
$nodes
);
field_attach_prepare_view
(
'node'
,
$nodes
,
$view_mode
,
$langcode
);
entity_prepare_view
(
'node'
,
$nodes
,
$langcode
);
$build
=
array
();
foreach
(
$nodes
as
$node
)
{
$build
[
'nodes'
][
$node
->
nid
]
=
node_view
(
$node
,
$view_mode
,
$langcode
);
...
...
modules/system/system.api.php
View file @
2a419f61
...
...
@@ -502,8 +502,10 @@ function hook_admin_paths_alter(&$paths) {
* The entities keyed by entity ID.
* @param $type
* The type of entities being loaded (i.e. node, user, comment).
* @param $langcode
* The language to display the entity in.
*/
function
hook_entity_prepare_view
(
$entities
,
$type
)
{
function
hook_entity_prepare_view
(
$entities
,
$type
,
$langcode
)
{
// Load a specific node into the user object for later theming.
if
(
$type
==
'user'
)
{
$nodes
=
mymodule_get_user_nodes
(
array_keys
(
$entities
));
...
...
modules/taxonomy/taxonomy.module
View file @
2a419f61
...
...
@@ -682,8 +682,8 @@ function taxonomy_term_view($term, $view_mode = 'full', $langcode = NULL) {
$langcode
=
$GLOBALS
[
'language_content'
]
->
language
;
}
field_attach_prepare_view
(
'taxonomy_term'
,
array
(
$term
->
tid
=>
$term
),
$view_mode
);
entity_prepare_view
(
'taxonomy_term'
,
array
(
$term
->
tid
=>
$term
));
field_attach_prepare_view
(
'taxonomy_term'
,
array
(
$term
->
tid
=>
$term
),
$view_mode
,
$langcode
);
entity_prepare_view
(
'taxonomy_term'
,
array
(
$term
->
tid
=>
$term
)
,
$langcode
);
$build
=
array
(
'#theme'
=>
'taxonomy_term'
,
...
...
modules/user/user.module
View file @
2a419f61
...
...
@@ -2523,8 +2523,8 @@ function user_build_content($account, $view_mode = 'full', $langcode = NULL) {
$account
->
content
=
array
();
// Build fields content.
field_attach_prepare_view
(
'user'
,
array
(
$account
->
uid
=>
$account
),
$view_mode
);
entity_prepare_view
(
'user'
,
array
(
$account
->
uid
=>
$account
));
field_attach_prepare_view
(
'user'
,
array
(
$account
->
uid
=>
$account
),
$view_mode
,
$langcode
);
entity_prepare_view
(
'user'
,
array
(
$account
->
uid
=>
$account
)
,
$langcode
);
$account
->
content
+=
field_attach_view
(
'user'
,
$account
,
$view_mode
,
$langcode
);
// Populate $account->content with a render() array.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment