1 image.field.inc image_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display)

Implements hook_field_formatter_view().

File

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

Code

function image_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();

  // Check if the formatter involves a link.
  if ($display['settings']['image_link'] == 'content') {
    $uri = entity_uri($entity_type, $entity);
  }
  elseif ($display['settings']['image_link'] == 'file') {
    $link_file = TRUE;
  }

  foreach ($items as $delta => $item) {
    if (!empty($item)) {
      // Add class for floating the image.
      if (!empty($display['settings']['image_float'])) {
        $item['attributes']['class'][] = 'align-' . $display['settings']['image_float'];
      }

      if (!empty($display['settings']['image_load'])) {
        // Although available in Chromium, the 'auto' value is not mentioned in
        // the specification. Since it may be subject to change, we recommend
        // not to use it until it gets officially included.
        if ($display['settings']['image_load'] != 'auto') {
          $item['attributes']['loading'] = $display['settings']['image_load'];
        }
      }

      if (isset($link_file)) {
        $uri = array(
          'path' => file_create_url($item['uri']),
          'options' => array(),
        );
      }
    }

    $element[$delta] = array(
      '#theme' => 'image_formatter',
      '#item' => $item,
      '#image_style' => $display['settings']['image_style'],
      '#path' => isset($uri) ? $uri : '',
    );
  }

  return $element;
}