function hook_entity_view

Act on entities being assembled before rendering.

Parameters

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

$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

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 drupal/core/modules/system/tests/modules/taxonomy_test/taxonomy_test.module
Implements hook_entity_view().
1 invocation of hook_entity_view()

File

drupal/core/includes/entity.api.php, line 199
Hooks provided the Entity module.

Code

function hook_entity_view(Drupal\Core\Entity\EntityInterface $entity, $view_mode, $langcode) {
  $entity->content['my_additional_field'] = array(
    '#markup' => $additional_field,
    '#weight' => 10,
    '#theme' => 'mymodule_my_additional_field',
  );
}