You are here

function galleria_field_formatter_prepare_view in Galleria 7

Implements hook_field_formatter_prepare_view().

Loads the attached nodes for node_reference fields so we can later access the image fields.

File

./galleria.module, line 515
A light-weight, customizable image gallery plugin for Drupal based on jQuery

Code

function galleria_field_formatter_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items, $displays) {
  if ($field['type'] == 'node_reference') {

    // Collect ids to load.
    $ids = array();
    foreach ($displays as $id => $display) {
      foreach ($items[$id] as $item) {
        if ($item['access']) {
          $ids[$item['nid']] = $item['nid'];
        }
      }
    }

    // Load the nodes.
    $nodes = node_load_multiple($ids);
    field_attach_prepare_view('node', $nodes, 'default', $langcode);
    entity_prepare_view('node', $nodes, $langcode);

    // Add the loaded nodes to the items.
    foreach ($displays as $id => $display) {
      foreach ($items[$id] as &$item) {
        if ($item['access']) {
          $item['node'] = $nodes[$item['nid']];
        }
      }
    }
  }
}