8.5.x entity.api.php hook_entity_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode)
8.0.x entity.api.php hook_entity_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode)
8.1.x entity.api.php hook_entity_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode)
8.2.x entity.api.php hook_entity_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode)
8.3.x entity.api.php hook_entity_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode)
8.4.x entity.api.php hook_entity_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode)
8.6.x entity.api.php hook_entity_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode)
7.x system.api.php hook_entity_view($entity, $type, $view_mode, $langcode)

Act on entities being assembled before rendering.


$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





Related topics

1 function implements hook_entity_view()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

taxonomy_test_entity_view in modules/simpletest/tests/taxonomy_test.module
Implements hook_entity_view().
6 invocations of hook_entity_view()
comment_build_content in modules/comment/comment.module
Builds a structured array representing the comment's content.
field_attach_view in modules/field/field.attach.inc
Returns a renderable array for the fields on an entity.
field_view_field in modules/field/field.module
Returns a renderable array for the value of a single field in an entity.
node_build_content in modules/node/node.module
Builds a structured array representing the node's content.
taxonomy_term_build_content in modules/taxonomy/taxonomy.module
Builds a structured array representing the term's content.

... See full list


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


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',


samundra’s picture

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.

ndmaque’s picture

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

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,

yookoala’s picture

Taxonomy terms are rendered differently. You cannot use this hook to alter the taxonomy term page.

batigolix’s picture

This was a bug that has been fixed in Drupal 7.17. It can now be rendered using hook_entity_view() as well.

See https://www.drupal.org/node/1067120#comment-6733930