diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-10-23 15:30:34 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-10-23 15:30:34 +0000 |
commit | 435585012c75bd5073d36cf6e7500864c6332bf8 (patch) | |
tree | ecbe63762742194192f4fcb1cc4b3a6d1b629b95 | |
parent | f914aef21b8801bf9a81ca3a4cd69484e12198c2 (diff) | |
download | brdo-435585012c75bd5073d36cf6e7500864c6332bf8.tar.gz brdo-435585012c75bd5073d36cf6e7500864c6332bf8.tar.bz2 |
#949576 by sun: Add missing hook_entity_view() and hook_entity_view_alter().
-rw-r--r-- | modules/comment/comment.api.php | 3 | ||||
-rw-r--r-- | modules/comment/comment.module | 4 | ||||
-rw-r--r-- | modules/node/node.api.php | 3 | ||||
-rw-r--r-- | modules/node/node.module | 4 | ||||
-rw-r--r-- | modules/system/system.api.php | 62 | ||||
-rw-r--r-- | modules/taxonomy/taxonomy.api.php | 28 | ||||
-rw-r--r-- | modules/taxonomy/taxonomy.module | 4 | ||||
-rw-r--r-- | modules/user/user.api.php | 4 | ||||
-rw-r--r-- | modules/user/user.module | 4 |
9 files changed, 113 insertions, 3 deletions
diff --git a/modules/comment/comment.api.php b/modules/comment/comment.api.php index d2b03911c..987d04673 100644 --- a/modules/comment/comment.api.php +++ b/modules/comment/comment.api.php @@ -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. diff --git a/modules/comment/comment.module b/modules/comment/comment.module index 70789b794..52549f974 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -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); } /** diff --git a/modules/node/node.api.php b/modules/node/node.api.php index 253c2e354..386c80028 100644 --- a/modules/node/node.api.php +++ b/modules/node/node.api.php @@ -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 */ diff --git a/modules/node/node.module b/modules/node/node.module index cce34c9e3..710a3851a 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -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); } /** diff --git a/modules/system/system.api.php b/modules/system/system.api.php index 20ddc4f62..c68d893d1 100644 --- a/modules/system/system.api.php +++ b/modules/system/system.api.php @@ -356,6 +356,68 @@ function hook_entity_query_alter($query) { } /** + * 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 may specify whether or not the paths they define in hook_menu() are diff --git a/modules/taxonomy/taxonomy.api.php b/modules/taxonomy/taxonomy.api.php index 6ceab8f80..1527e487c 100644 --- a/modules/taxonomy/taxonomy.api.php +++ b/modules/taxonomy/taxonomy.api.php @@ -183,5 +183,33 @@ function hook_taxonomy_term_delete($term) { } /** + * 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". */ diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module index b36bca9c3..1e0cf45ad 100644 --- a/modules/taxonomy/taxonomy.module +++ b/modules/taxonomy/taxonomy.module @@ -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; } diff --git a/modules/user/user.api.php b/modules/user/user.api.php index d6723db14..722fb31dc 100644 --- a/modules/user/user.api.php +++ b/modules/user/user.api.php @@ -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. diff --git a/modules/user/user.module b/modules/user/user.module index adfb493c1..c0372e658 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -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); } /** |