You are here

function image_field_prepare_view in Drupal 7

Implements hook_field_prepare_view().

File

modules/image/image.field.inc, line 201
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])) {
      $fid = 0;

      // Use the default for the instance if one is available.
      if (!empty($instances[$id]['settings']['default_image'])) {
        $fid = $instances[$id]['settings']['default_image'];
      }
      elseif (!empty($field['settings']['default_image'])) {
        $fid = $field['settings']['default_image'];
      }

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