? image-90358.patch
Index: contrib/image_attach/image_attach.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/image/contrib/image_attach/image_attach.module,v
retrieving revision 1.47
diff -u -p -r1.47 image_attach.module
--- contrib/image_attach/image_attach.module	22 Mar 2009 18:36:37 -0000	1.47
+++ contrib/image_attach/image_attach.module	17 Jun 2009 18:53:05 -0000
@@ -170,6 +170,29 @@ function image_attach_form_alter(&$form,
       '#default_value' => variable_get('image_attach_weight_body_'. $form['#node_type']->type, 0),
       '#description' => t('This value determines the order of the image when displayed in the body.'),
     );
+    if(module_exists('image_gallery')) {
+      $form['image_attach']['image_gallery'] = array(
+        '#type' => 'fieldset',
+        '#title' => t('Image gallery'),
+        '#collapsible' => TRUE,
+        '#collapsed' => TRUE,
+      );
+      $image_attach_gallery_defaults_options =  array(
+        0 => t('Use nodetype gallery'),
+        1 => t('Use per node gallery'),
+        2 => t('Use per node gallery, if empty use nodetype gallery'),
+      );
+      $form['image_attach']['image_gallery']['image_attach_gallery_defaults'] = array(
+        '#type' => 'radios',
+        '#title' => t('Add images to gallery'),
+        '#default_value' => variable_get('image_attach_gallery_defaults_'. $form['#node_type']->type, 0),
+        '#options' => $image_attach_gallery_defaults_options,
+      );
+      $form['image_attach']['image_gallery']['image_attach_gallery'] = taxonomy_form(_image_gallery_get_vid());
+      $form['image_attach']['image_gallery']['image_attach_gallery']['#default_value'] = variable_get('image_attach_gallery_'. $form['#node_type']->type, 0);
+      $form['image_attach']['image_gallery']['image_attach_gallery']['#weight'] = 0;
+      $form['image_attach']['image_gallery']['image_attach_gallery']['#description'] = t('Choose an image gallery to place the new image in.');
+    }
   }
   // Node edit form.
   else if (isset($form['type']['#value']) && $form['type']['#value'] != 'image') {
@@ -228,6 +251,14 @@ function image_attach_form_alter(&$form,
         $value => '',
         '#description' => t('The title the image will be shown with.')
       );
+      if(module_exists('image_gallery') && variable_get('image_attach_gallery_defaults_'. $form['type']['#value'], 0)) {
+        $form['image_attach']['image_gallery'] = taxonomy_form(_image_gallery_get_vid());
+        if (is_array($image->taxonomy)) {
+          $image_gallery_value = array_keys($image->taxonomy);
+          $form['image_attach']['image_gallery']['#value'] = $image_gallery_value[0];
+        }
+        $form['image_attach']['image_gallery']['#description'] = t('Choose an image gallery to place the new image in.');
+      }
     }
   }
 }
@@ -247,6 +278,27 @@ function image_attach_validate($form, &$
     // This func now does all the things to initialize an image properly
     $image = image_create_node_from($file->filepath, $image_title, '');
     if ($image && !form_get_errors()) {
+      // If image node is saved add taxonomy if needed
+      $image_attach_gallery_defaults_type = variable_get('image_attach_gallery_defaults_'. $form['type']['#value'], 0);
+      switch($image_attach_gallery_defaults_type) {
+        case 0:
+        case 2:
+          $image_attach_gallery_type = variable_get('image_attach_gallery_'. $form['type']['#value'], 0);
+          $gallery_tid = $image_attach_gallery_type;
+          if ($image_attach_gallery_defaults_type == 2 && !$image_attach_gallery_type) {
+            $gallery_tid = $_POST['image_gallery'];            
+          }
+          break;
+        case 1:
+          $gallery_tid = $_POST['image_gallery'];
+          break;            
+      }
+      if ($gallery_tid) {
+        $gallery = taxonomy_get_term($gallery_tid);
+        if ($gallery) {
+          taxonomy_node_save($image, array($gallery->tid));
+        }
+      }
       drupal_set_message(t("Created new image to attach to this node. !image_link", array('!image_link' => l($image_title, 'node/'. $image->nid) )));
       form_set_value($form['image_attach']['iid'], $image->nid, $form_state);
     }
