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
43558501
Commit
43558501
authored
Oct 23, 2010
by
webchick
Browse files
#949576
by sun: Add missing hook_entity_view() and hook_entity_view_alter().
parent
f914aef2
Changes
9
Hide whitespace changes
Inline
Side-by-side
modules/comment/comment.api.php
View file @
43558501
...
...
@@ -68,6 +68,8 @@ function hook_comment_load($comments) {
* View mode, e.g. 'full', 'teaser'...
* @param $langcode
* The language code used for rendering.
*
* @see hook_entity_view()
*/
function
hook_comment_view
(
$comment
,
$view_mode
,
$langcode
)
{
// how old is the comment
...
...
@@ -90,6 +92,7 @@ function hook_comment_view($comment, $view_mode, $langcode) {
* A renderable array representing the comment.
*
* @see comment_view()
* @see hook_entity_view_alter()
*/
function
hook_comment_view_alter
(
&
$build
)
{
// Check for the existence of a field added by another module.
...
...
modules/comment/comment.module
View file @
43558501
...
...
@@ -939,7 +939,8 @@ function comment_view($comment, $node, $view_mode = 'full', $langcode = NULL) {
}
// Allow modules to modify the structured comment.
drupal_alter
(
'comment_view'
,
$build
);
$type
=
'comment'
;
drupal_alter
(
array
(
'comment_view'
,
'entity_view'
),
$build
,
$type
);
return
$build
;
}
...
...
@@ -983,6 +984,7 @@ function comment_build_content($comment, $node, $view_mode = 'full', $langcode =
// Allow modules to make their own additions to the comment.
module_invoke_all
(
'comment_view'
,
$comment
,
$view_mode
,
$langcode
);
module_invoke_all
(
'entity_view'
,
$comment
,
'comment'
,
$view_mode
,
$langcode
);
}
/**
...
...
modules/node/node.api.php
View file @
43558501
...
...
@@ -759,6 +759,8 @@ function hook_node_submit($node, $form, &$form_state) {
* @param $langcode
* The language code used for rendering.
*
* @see hook_entity_view()
*
* @ingroup node_api_hooks
*/
function
hook_node_view
(
$node
,
$view_mode
,
$langcode
)
{
...
...
@@ -785,6 +787,7 @@ function hook_node_view($node, $view_mode, $langcode) {
* A renderable array representing the node content.
*
* @see node_view()
* @see hook_entity_view_alter()
*
* @ingroup node_api_hooks
*/
...
...
modules/node/node.module
View file @
43558501
...
...
@@ -1270,7 +1270,8 @@ function node_view($node, $view_mode = 'full', $langcode = NULL) {
}
// Allow modules to modify the structured node.
drupal_alter
(
'node_view'
,
$build
);
$type
=
'node'
;
drupal_alter
(
array
(
'node_view'
,
'entity_view'
),
$build
,
$type
);
return
$build
;
}
...
...
@@ -1343,6 +1344,7 @@ function node_build_content($node, $view_mode = 'full', $langcode = NULL) {
// Allow modules to make their own additions to the node.
module_invoke_all
(
'node_view'
,
$node
,
$view_mode
,
$langcode
);
module_invoke_all
(
'entity_view'
,
$node
,
'node'
,
$view_mode
,
$langcode
);
}
/**
...
...
modules/system/system.api.php
View file @
43558501
...
...
@@ -355,6 +355,68 @@ function hook_entity_query_alter($query) {
$query
->
executeCallback
=
'my_module_query_callback'
;
}
/**
* Act on entities being assembled before rendering.
*
* @param $entity
* The entity object.
* @param $type
* The type of entity being rendered (i.e. node, user, comment).
* @param $view_mode
* The view mode the entity is rendered in.
* @param $langcode
* The language code used for rendering.
*
* The module may add elements to $entity->content prior to rendering. The
* structure of $entity->content is a renderable array as expected by
* drupal_render().
*
* @see hook_entity_view_alter()
* @see hook_comment_view()
* @see hook_node_view()
* @see hook_user_view()
*/
function
hook_entity_view
(
$entity
,
$type
,
$view_mode
,
$langcode
)
{
$entity
->
content
[
'my_additional_field'
]
=
array
(
'#markup'
=>
$additional_field
,
'#weight'
=>
10
,
'#theme'
=>
'mymodule_my_additional_field'
,
);
}
/**
* Alter the results of ENTITY_view().
*
* This hook is called after the content has been assembled in a structured
* array and may be used for doing processing which requires that the complete
* entity content structure has been built.
*
* If a module wishes to act on the rendered HTML of the entity rather than the
* structured content array, it may use this hook to add a #post_render
* callback. Alternatively, it could also implement hook_preprocess_ENTITY().
* See drupal_render() and theme() for details.
*
* @param $build
* A renderable array representing the entity content.
* @param $type
* The type of entity being rendered (i.e. node, user, comment).
*
* @see hook_entity_view()
* @see hook_comment_view_alter()
* @see hook_node_view_alter()
* @see hook_taxonomy_term_view_alter()
* @see hook_user_view_alter()
*/
function
hook_entity_view_alter
(
&
$build
,
$type
)
{
if
(
$build
[
'#view_mode'
]
==
'full'
&&
isset
(
$build
[
'an_additional_field'
]))
{
// Change its weight.
$build
[
'an_additional_field'
][
'#weight'
]
=
-
10
;
// Add a #post_render callback to act on the rendered HTML of the entity.
$build
[
'#post_render'
][]
=
'my_module_node_post_render'
;
}
}
/**
* Define administrative paths.
*
...
...
modules/taxonomy/taxonomy.api.php
View file @
43558501
...
...
@@ -182,6 +182,34 @@ function hook_taxonomy_term_delete($term) {
db_delete
(
'term_synoynm'
)
->
condition
(
'tid'
,
$term
->
tid
)
->
execute
();
}
/**
* Alter the results of taxonomy_term_view().
*
* This hook is called after the content has been assembled in a structured
* array and may be used for doing processing which requires that the complete
* taxonomy term content structure has been built.
*
* If the module wishes to act on the rendered HTML of the term rather than the
* structured content array, it may use this hook to add a #post_render
* callback. Alternatively, it could also implement
* hook_preprocess_taxonomy_term(). See drupal_render() and theme()
* documentation respectively for details.
*
* @param $build
* A renderable array representing the node content.
*
* @see hook_entity_view_alter()
*/
function
hook_taxonomy_term_view_alter
(
&
$build
)
{
if
(
$build
[
'#view_mode'
]
==
'full'
&&
isset
(
$build
[
'an_additional_field'
]))
{
// Change its weight.
$build
[
'an_additional_field'
][
'#weight'
]
=
-
10
;
}
// Add a #post_render callback to act on the rendered HTML of the term.
$build
[
'#post_render'
][]
=
'my_module_node_post_render'
;
}
/**
* @} End of "addtogroup hooks".
*/
modules/taxonomy/taxonomy.module
View file @
43558501
...
...
@@ -665,6 +665,10 @@ function taxonomy_term_view($term, $view_mode = 'full', $langcode = NULL) {
$build
[
'#attached'
][
'css'
][]
=
drupal_get_path
(
'module'
,
'taxonomy'
)
.
'/taxonomy.css'
;
// Allow modules to modify the structured term.
$type
=
'taxonomy_term'
;
drupal_alter
(
array
(
'taxonomy_term_view'
,
'entity_view'
),
$build
,
$type
);
return
$build
;
}
...
...
modules/user/user.api.php
View file @
43558501
...
...
@@ -316,6 +316,9 @@ function hook_user_logout($account) {
* View mode, e.g. 'full'.
* @param $langcode
* The language code used for rendering.
*
* @see hook_user_view_alter()
* @see hook_entity_view()
*/
function
hook_user_view
(
$account
,
$view_mode
,
$langcode
)
{
if
(
user_access
(
'create blog content'
,
$account
))
{
...
...
@@ -344,6 +347,7 @@ function hook_user_view($account, $view_mode, $langcode) {
* A renderable array representing the user.
*
* @see user_view()
* @see hook_entity_view_alter()
*/
function
hook_user_view_alter
(
&
$build
)
{
// Check for the existence of a field added by another module.
...
...
modules/user/user.module
View file @
43558501
...
...
@@ -2452,7 +2452,8 @@ function user_view($account, $view_mode = 'full', $langcode = NULL) {
);
// Allow modules to modify the structured user.
drupal_alter
(
'user_view'
,
$build
);
$type
=
'user'
;
drupal_alter
(
array
(
'user_view'
,
'entity_view'
),
$build
,
$type
);
return
$build
;
}
...
...
@@ -2483,6 +2484,7 @@ function user_build_content($account, $view_mode = 'full', $langcode = NULL) {
// Populate $account->content with a render() array.
module_invoke_all
(
'user_view'
,
$account
,
$view_mode
,
$langcode
);
module_invoke_all
(
'entity_view'
,
$account
,
'user'
,
$view_mode
,
$langcode
);
}
/**
...
...
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