Index: imagefield.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imagefield/imagefield.module,v
retrieving revision 1.89
diff -u -r1.89 imagefield.module
--- imagefield.module	21 Mar 2009 03:26:41 -0000	1.89
+++ imagefield.module	24 Mar 2009 19:28:02 -0000
@@ -173,26 +173,44 @@
   // Start with the FileField widget as a basic start.
   $element = module_invoke('filefield', 'widget', $form, $form_state, $field, $items, $delta);
 
+  // Add ImageField specific validators.
+  $element['#upload_validators'] = array_merge($element['#upload_validators'], imagefield_widget_upload_validators($field));
+
+  return $element;
+}
+
+/**
+ * Get the additional upload validators for an image field.
+ *
+ * @param $field
+ *   The CCK field array.
+ * @return
+ *   An array suitable for passing to file_save_upload() or the file field
+ *   element's '#upload_validators' property.
+ */
+function imagefield_widget_upload_validators($field) {
+  $validators = array();
+
   // Ensure that only web images are supported.
   $web_extensions = array('jpg', 'jpeg', 'gif', 'png');
-  $extensions = array_filter(explode(' ', $element['#upload_validators']['filefield_validate_extensions'][0]));
+  $extensions = array_filter(explode(' ', $field['widget']['file_extensions']));
   if (empty($extensions)) {
     $extensions = $web_extensions;
   }
-  $element['#upload_validators']['filefield_validate_extensions'][0] = implode(' ', array_intersect($extensions, $web_extensions));
+  $validators['filefield_validate_extensions'][0] = implode(' ', array_intersect($extensions, $web_extensions));
 
   // Add the image validator as a basic safety check.
-  $element['#upload_validators']['filefield_validate_is_image'] = array();
+  $validators['filefield_validate_is_image'] = array();
 
   // Add validators for resolutions.
   if (!empty($field['widget']['max_resolution']) || !empty($field['widget']['min_resolution'])) {
-    $element['#upload_validators']['filefield_validate_image_resolution'] = array(
+    $validators['filefield_validate_image_resolution'] = array(
       $field['widget']['max_resolution'],
       $field['widget']['min_resolution'],
     );
   }
 
-  return $element;
+  return $validators;
 }
 
 /**
