Index: mm_content.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/media_mover/mm_content/mm_content.module,v retrieving revision 1.1.2.14 diff -u -p -r1.1.2.14 mm_content.module --- mm_content.module 8 Jul 2008 18:36:51 -0000 1.1.2.14 +++ mm_content.module 9 Jul 2008 16:01:27 -0000 @@ -159,7 +159,7 @@ function mm_content_harvest($action, $co * @TODO support other CCK types than just text */ function mm_content_node_save($configuration, $file) { - + // we have to have an NID if ($file['data']['nid']) { // get the node $node = node_load($file['data']['nid']); @@ -167,14 +167,56 @@ function mm_content_node_save($configura $field = content_fields($configuration['mm_config_save_field']); switch ($field['type']) { case 'text': - $node->{$field['field_name']} = array( array('value' => $file['process_file'])); + $node->{$field['field_name']} = array(array('value' => $file['process_file'])); break; + + // handle image field case + case 'image': + mm_content_field_image($node, $file, $configuration); + break; + } // save the node node_save($node); - + // clear the cache + cache_clear_all('content:'. $node->nid .':'. $node->vid, 'cache_content'); + // return the file return $file['storage_file']; - } + } + // set an alert + watchdog('mm_content', t('Media Mover did not pass a node ID for storing data in a CCK field: !file', array('!file', l(t($file['mmfid']), 'admin/media_mover/file/edit/'. $file['mmfid'])))); + return false; +} + + +/** + * helper function to map cck image fields + * @param object $node + * drupal node object + * @param string $field + * the cck field name that we're storing to + * @param array $file + * media mover file array + * @param array $configuration + * media mover configuration array + * @return unknown + */ +function mm_content_field_image(&$node, $field, $file, $configuration) { + + // now create the imagefield array + $imagefield_file = array( + 'fid' => db_next_id('{files}_fid'), + 'alt' => '', + 'title' => '', + 'session_id' => 0, + 'filename' => basename($file['process_file']), + 'filepath' => $file['process_file'], + 'preview' => $file['process_file'], + 'filesize' => filesize($file['process_file']), + 'filemime' => mimedetect_mime($file['process_file']), + ); + + $node->{$field}[] = $imagefield_file; }