8.5.x entity.api.php hook_entity_prepare_view($entity_type_id, array $entities, array $displays, $view_mode)
8.0.x entity.api.php hook_entity_prepare_view($entity_type_id, array $entities, array $displays, $view_mode)
8.1.x entity.api.php hook_entity_prepare_view($entity_type_id, array $entities, array $displays, $view_mode)
8.2.x entity.api.php hook_entity_prepare_view($entity_type_id, array $entities, array $displays, $view_mode)
8.3.x entity.api.php hook_entity_prepare_view($entity_type_id, array $entities, array $displays, $view_mode)
8.4.x entity.api.php hook_entity_prepare_view($entity_type_id, array $entities, array $displays, $view_mode)
8.6.x entity.api.php hook_entity_prepare_view($entity_type_id, array $entities, array $displays, $view_mode)
7.x system.api.php hook_entity_prepare_view($entities, $type, $langcode)

Act on entities as they are being prepared for view.

Allows you to operate on multiple entities as they are being prepared for view. Only use this if attaching the data during the entity_load() phase is not appropriate, for example when attaching other 'entity' style objects.

Parameters

$entities: The entities keyed by entity ID.

$type: The type of entities being loaded (i.e. node, user, comment).

$langcode: The language to display the entity in.

Related topics

3 invocations of hook_entity_prepare_view()
entity_prepare_view in includes/common.inc
Invoke hook_entity_prepare_view().
field_attach_prepare_view in modules/field/field.attach.inc
Prepare field data prior to display.
field_view_field in modules/field/field.module
Returns a renderable array for the value of a single field in an entity.

File

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

Code

function hook_entity_prepare_view($entities, $type, $langcode) {

  // Load a specific node into the user object for later theming.
  if ($type == 'user') {
    $nodes = mymodule_get_user_nodes(array_keys($entities));
    foreach ($entities as $uid => $entity) {
      $entity->user_node = $nodes[$uid];
    }
  }
}

Comments

andriyun’s picture

Hello!
I have a node type with multiple link field
Before node render i want programmatically add to this field, a few regular context links.

function deweb_entity_prepare_view($entities, $type) {
  if ($type == 'node'){
    foreach ($entities as $uid => &$entity) {
      $entity->field_link_prod['und'][] = array(
        'url' => $url,
        'title' => $title,
        'attributes' => array(),
        'display_url' => $url,
        'html' => TRUE,
        );
    }
  }
}

Will be correct do it in this hook?