1.20.x image.field.inc image_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items)

Implements hook_field_prepare_view().

File

modules/image/image.field.inc, line 284
Implement an image field, based on the file module's file field.

Code

function image_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items) {
  // If there are no files specified at all, use the default.
  foreach ($entities as $id => $entity) {
    if (empty($items[$id])) {
      $default_uri = '';
      // Use the default for the instance if one is available.
      if (!empty($instances[$id]['settings']['default_image'])) {
        $default_uri = $instances[$id]['settings']['default_image'];
      }
      // Otherwise, use the default for the field.
      elseif ($field['settings']['default_image']) {
        $default_uri = $field['settings']['default_image'];
      }

      // Add the default image if one is found.
      if ($default_uri) {
        $items[$id][0] = (array) array(
          'uri' => $default_uri,
          'is_default' => TRUE,
          'alt' => '',
          'title' => '',
        );
      }
    }
  }
}