#949576 by sun: Add missing hook_entity_view() and hook_entity_view_alter().

merge-requests/26/head
Angie Byron 2010-10-23 15:30:34 +00:00
parent f914aef21b
commit 435585012c
9 changed files with 113 additions and 3 deletions

View File

@ -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.

View File

@ -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);
}
/**

View File

@ -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
*/

View File

@ -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);
}
/**

View File

@ -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.
*

View File

@ -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".
*/

View File

@ -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;
}

View File

@ -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.

View File

@ -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);
}
/**