Index: imagefield.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imagefield/imagefield.module,v
retrieving revision 1.30.2.6.2.16
diff -u -r1.30.2.6.2.16 imagefield.module
--- imagefield.module	22 Apr 2007 09:45:30 -0000	1.30.2.6.2.16
+++ imagefield.module	10 May 2007 18:13:52 -0000
@@ -261,13 +261,61 @@
         '#default_value' =>  $widget['custom_title'] ? $widget['custom_title'] : 0,
         '#description' => t('Enable custom title text for images. Filename will be used if not checked.'),
       );
+      $form['default'] = array(
+        '#type' => 'fieldset',
+        '#title' => t('Default image'),
+        '#collapsible' => TRUE,
+        '#collapsed' => !$widget['use_default_image'],
+      );
+      // Present a thumbnail of the current default image.
+      $form['default']['use_default_image'] = array(
+        '#type' => 'checkbox',
+        '#title' => t('Use default image'),
+        '#default_value' =>  $widget['use_default_image'],
+        '#description' => t('Check here if you want to use a image as default.'),
+      );
+      if (!empty($widget['default_image'])) {
+        $form['default']['default_image_thumbnail'] = array(
+          '#type' => 'markup',
+          '#value' => theme('imagefield_image', $widget['default_image'], '', '', array('width' => '150'), FALSE),
+        );
+      }
+      $form['default']['default_image_upload'] = array(
+        '#type'  => 'file',
+        '#title' => t('Upload image'),
+        '#description' => t('Choose a image that will be used as default.'),
+      );
+      // We set this value on 'validate' so we can get cck to add it
+      // as a standard field setting.
+      $form['default_image'] = array(
+        '#type' => 'value',
+        '#value' => $widget['default_image'],
+      );
       return $form;
 
     case 'validate':
+      // We save the upload here because we can't know the correct
+      // file path until we save the file.
+      if ($file = file_check_upload('default_image_upload')) {
+        $filepath = file_create_path($widget['image_path']);
+        if ($file = file_save_upload('default_image_upload', $filepath)) {
+          form_set_value(array('#parents' => array('default_image')), (array) $file);
+        }
+      }
       break;
 
     case 'save':
-      return array('max_resolution', 'image_path', 'file_extensions', 'custom_alt', 'custom_title');
+      return array('max_resolution', 'image_path', 'file_extensions', 'custom_alt', 'custom_title', 'use_default_image', 'default_image');
+  }
+}
+
+/**
+ * Implementation of hook_form_alter(). Set the appropriate
+ * attibutes to allow file uploads on the field settings form.
+ */
+function imagefield_form_alter($form_id, &$form) {
+  if ($form_id == '_content_admin_field') {
+    $form['#attributes'] = array('enctype' => 'multipart/form-data');
   }
 }
 
@@ -673,11 +721,16 @@
  *
  */
 function imagefield_field_formatter($field, $item, $formatter) {
-  if (empty($item['fid'])) {
-    return '';
+  if (!empty($item['fid'])) {
+    $file = _imagefield_file_load($item['fid']);
+  }
+  // If there is no image on the database, use default.
+  elseif ($field['widget']['use_default_image'] && is_array($field['widget']['default_image'])) {
+    $file = $field['widget']['default_image'];
+  }
+  if (!empty($file['filepath'])) {
+    return theme('imagefield_image', $file, $item['alt'], $item['title']);
   }
-  $file = _imagefield_file_load($item['fid']);
-  return theme('imagefield_image', $file, $item['alt'], $item['title']);
 }
 
 
@@ -726,8 +779,6 @@
     return '<img src="'. check_url($url) .'" alt="'.
         check_plain($alt) .'" title="'. check_plain($title) .'" '. $image_attributes . $attributes .' />';
   }
-  // we could display default image here...
-  return '';
 }
 
 /**
