function hook_entity_prepare_view
Same name in other branches
- 9 core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_prepare_view()
- 8.9.x core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_prepare_view()
- 10 core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_prepare_view()
- 11.x core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_prepare_view()
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
1 invocation of hook_entity_prepare_view()
- entity_prepare_view in includes/
common.inc - Invoke hook_entity_prepare_view().
File
-
modules/
system/ system.api.php, line 547
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];
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.