Act on entities being assembled before rendering.

Act on entities being assembled before rendering.


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