Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / hook / entity_prepare_view.twig
1 /**
2  * Implements hook_entity_prepare_view().
3  */
4 function {{ machine_name }}_entity_prepare_view($entity_type_id, array $entities, array $displays, $view_mode) {
5   // Load a specific node into the user object for later theming.
6   if (!empty($entities) && $entity_type_id == 'user') {
7     // Only do the extra work if the component is configured to be
8     // displayed. This assumes a 'mymodule_addition' extra field has been
9     // defined for the entity bundle in hook_entity_extra_field_info().
10     $ids = [];
11     foreach ($entities as $id => $entity) {
12       if ($displays[$entity->bundle()]->getComponent('mymodule_addition')) {
13         $ids[] = $id;
14       }
15     }
16     if ($ids) {
17       $nodes = mymodule_get_user_nodes($ids);
18       foreach ($ids as $id) {
19         $entities[$id]->user_node = $nodes[$id];
20       }
21     }
22   }
23 }