From 5d256de0c7218c9bab31c4c1a5f59ef8e87bdfd7 Tue, 19 Apr 2011 11:05:49 +0200
From: SylvainLecoy <sylvain.lecoy@fr.ibm.com>
Date: Tue, 19 Apr 2011 11:05:17 +0200
Subject: [PATCH] - Patch #992792 by Sylvain Lecoy: Image field should implements image_url_plain view mode.

diff --git a/modules/image/image.field.inc b/modules/image/image.field.inc
index 07cc1e0..74ff236 100644
--- a/modules/image/image.field.inc
+++ b/modules/image/image.field.inc
@@ -414,6 +414,11 @@
       'field types' => array('image'),
       'settings' => array('image_style' => '', 'image_link' => ''),
     ),
+    'image_url_plain' => array(
+      'label' => t('URL to image'),
+      'field types' => array('image'),
+      'settings' => array('image_style' => '', 'image_link' => ''),
+    ),
   );
 
   return $formatters;
@@ -435,17 +440,19 @@
     '#options' => $image_styles,
   );
 
-  $link_types = array(
-    'content' => t('Content'),
-    'file' => t('File'),
-  );
-  $element['image_link'] = array(
-    '#title' => t('Link image to'),
-    '#type' => 'select',
-    '#default_value' => $settings['image_link'],
-    '#empty_option' => t('Nothing'),
-    '#options' => $link_types,
-  );
+  if ($display['type'] == 'image') {
+    $link_types = array(
+      'content' => t('Content'),
+      'file' => t('File'),
+    );
+    $element['image_link'] = array(
+      '#title' => t('Link image to'),
+      '#type' => 'select',
+      '#default_value' => $settings['image_link'],
+      '#empty_option' => t('Nothing'),
+      '#options' => $link_types,
+    );
+  }
 
   return $element;
 }
@@ -489,29 +496,45 @@
 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;
-  }
+  switch ($display['type']) {
+    case 'image':
+      // 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 (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 : '',
-    );
-  }
+      foreach ($items as $delta => $item) {
+        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 : '',
+        );
+      }
+      break;
 
+    case 'image_url_plain':
+      foreach ($items as $delta => $item) {
+        $style_path = image_style_path($display['settings']['image_style'], $item['uri']);
+        if (!file_exists($style_path)) {
+          $style_path = image_style_url($display['settings']['image_style'], $item['uri']);
+        }
+        $element[$delta] = array(
+          '#markup' => empty($style_path) ? '' : file_create_url($style_path),
+        );
+      }
+      break;
+  }
+    
   return $element;
 }
 
