hook_entity_view

7 system.api.php hook_entity_view($entity, $type, $view_mode, $langcode)
8 entity.api.php hook_entity_view($entity, $type, $view_mode, $langcode)

Act on entities being assembled before rendering.

Parameters

$entity: The entity object.

$type: The type of entity being rendered (i.e. node, user, comment).

$view_mode: The view mode the entity is rendered in.

$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 also

hook_entity_view_alter()

hook_comment_view()

hook_node_view()

hook_user_view()

Related topics

3 invocations of hook_entity_view()

File

modules/system/system.api.php, line 407
Hooks provided by Drupal core and the System module.

Code

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',
  );
}

Comments

Find the usage of hook_entity_view in my personal website

I have written a tutorial that will show how to use the hook_entity_view in custom entity module.

The link to tutorial is http://www.samundra.com.np/solved-how-to-use-hook_entity_view-in-drupal7....

Please post your feedback and comments that will help me improve writing more tutorials and how tos.

@samundra Thanks for the

@samundra
Thanks for the tutorial.
In my case i wanted to attach a form to the end of the contact page.
It really was this simple...

<?php
function aat_contact_entity_view( $entity, $type, $view_mode, $langcode ) {
 
  switch (
$type) {
    case
'node':
      if(
$entity->nid == variable_get('aat_contact_contact_nid',0)) {

       
$output = drupal_get_form('aat_contact_contact');
       
       
// create a new content field and stick the html in it
        // sink it to the bottom of the node
       
$entity->content['a_new_field'] = array(
             
'#markup' => drupal_render($output),
             
'#weight' => 99,
        );
      }
      break;
  }
}
?>

Login or register to post comments