/Drupal 8

function hook_entity_view

hook_entity_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode)

Act on entities being assembled before rendering.


&$build: A renderable array representing the entity content. The module may add elements to $build prior to rendering. The structure of $build is a renderable array as expected by drupal_render().

\Drupal\Core\Entity\EntityInterface $entity: The entity object.

\Drupal\Core\Entity\Display\EntityViewDisplayInterface $display: The entity view display holding the display options configured for the entity components.

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

See also



Related topics

Entity CRUD, editing, and view hooks
Hooks used in various entity operations.
Define functions that alter the behavior of Drupal core.


core/lib/Drupal/Core/Entity/entity.api.php, line 1290
Hooks and documentation related to entities.


function hook_entity_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode) {
  // Only do the extra work if the component is configured to be displayed.
  // This assumes a 'mymodule_addition' extra field has been defined for the
  // entity bundle in hook_entity_extra_field_info().
  if ($display->getComponent('mymodule_addition')) {
    $build['mymodule_addition'] = array(
      '#markup' => mymodule_addition($entity),
      '#theme' => 'mymodule_my_additional_field',

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.