Index: emfield/contrib/emthumb/emthumb.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/emfield/contrib/emthumb/emthumb.info,v
retrieving revision 1.1.4.4
diff -u -p -r1.1.4.4 emthumb.info
--- emfield/contrib/emthumb/emthumb.info	27 Aug 2008 11:47:38 -0000	1.1.4.4
+++ emfield/contrib/emthumb/emthumb.info	16 Dec 2008 23:05:56 -0000
@@ -2,5 +2,6 @@
 name = Embedded Media Thumbnail
 description = Allows custom thumbnails for Embedded Media Fields (Not ready for Drupal 6 yet).
 dependencies[] = emfield
+dependencies[] = filefield
 package = CCK
-core = 5.x
\ No newline at end of file
+core = 6.x
\ No newline at end of file
Index: emfield/contrib/emthumb/emthumb.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/emfield/contrib/emthumb/emthumb.module,v
retrieving revision 1.7.2.7
diff -u -p -r1.7.2.7 emthumb.module
--- emfield/contrib/emthumb/emthumb.module	17 Nov 2008 22:06:20 -0000	1.7.2.7
+++ emfield/contrib/emthumb/emthumb.module	16 Dec 2008 23:05:56 -0000
@@ -97,7 +97,15 @@ function _emthumb_file_update($node, &$f
   return $file;
 }
 
+/**
+ *  Custom Thumnail, add settings, delegate to file field
+ */
 function emthumb_emfield_field_extra($op, $node, $field, &$items, $teaser, $page) {
+  $element = filefield_field($op, $node, $field, $items, $teaser, $page);
+  return $element;
+
+  // Legacy code, for reference.
+  // @TODO: Remove when done.
   switch ($op) {
     case 'submit':
     case 'validate':
@@ -135,7 +143,7 @@ function emthumb_emfield_field_extra($op
         foreach ($items as $delta => $file) {
           $thumbnail = _emthumb_file_load($file['data']['emthumb']['fid']);
           if (isset($thumbnail['filepath'])) {
-    $options = array('absolute' => TRUE);
+            $options = array('absolute' => TRUE);
             $thumbnail['filepath'] = url($thumbnail['filepath'], $options);
             $output[$delta]['thumbnail'] = $thumbnail;
           }
@@ -173,8 +181,14 @@ function emthumb_emfield_field_extra($op
 /**
  *  This provides extra widget settings to emfields.
  *  A checkbox to allow custom thumbnails, max resolution, image path, allow custom alt tags, allow custom title tags.
+ *  Add emthumb widget settings, then delegate to file field
  */
 function emthumb_emfield_widget_settings_extra($op, $widget) {
+  $element = filefield_widget_settings($op, $widget);
+  return $element;
+
+  // Legacy code, for reference.
+  // @TODO: Remove when done.
   switch ($op) {
     case 'form':
       $form = array();
@@ -238,9 +252,24 @@ function emthumb_emfield_widget_settings
 }
 
 /**
- *  when editing a node with an emfield, this will add our custom thumbnail upload form if allowed.
+ *  When editing a node with an emfield, this will add our custom thumbnail upload form if allowed.
+ *  Assign default properties and delegate to filefield.
+ *  emfield.cck.inc invokes this function, but does not yet pass it the right parameters,
+ *  so it will have to be changed too ?
  */
+
 function emthumb_emfield_widget_extra($op, &$node, $field, &$items) {
+  // add default values to items.
+  if (empty($items[$delta])) {
+    $items[$delta] = array('alt' => '', 'title' => '');
+  }
+
+  $element = filefield_widget($form, $form_state, $field, $items, $delta);
+
+  return $element;
+
+  // Legacy code, for reference.
+  // @TODO: Remove when done.
   $fieldname = $field['field_name'];
   $content_type = $field['type_name'];
   drupal_set_message("op: $op");
@@ -634,3 +663,23 @@ if (!function_exists('upload_file_downlo
   }
 }
 
+/**
+* Implementation of hook_elements().
+*/
+function emthumb_elements() {
+  $elements = array();
+  $elements['emthumb_widget'] =  array(
+    // Indicate to FormAPI that this element needs processing and is not simply a render element.
+    '#input' => TRUE,
+    // specify the return structure of the element (experimental, unused in releases).
+    '#returns' => array('array' => array('fid' => 'int', 'title' => 'string', 'alt' => 'string')),
+    // Delegate element processing to filefield. Filefield will include
+    '#process' => array('filefield_widget_process', 'emthumb_widget_widget_process'),
+    // See emthumb_widget[#process] documentation.
+    '#value_callback' => 'filefield_widget_value',
+    // delegate to filefield...
+    '#element_validate' => array('filefield_widget_validate', 'emthumb_widget_validate'),
+    '#description' => t('Changes made to the attachments are not permanent until you save this post.'),
+  );
+  return $elements;
+}
