Index: attachment.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/attachment/attachment.module,v
retrieving revision 1.10
diff -u -r1.10 attachment.module
--- attachment.module	31 Oct 2005 15:29:35 -0000	1.10
+++ attachment.module	7 Dec 2005 04:12:40 -0000
@@ -1,20 +1,35 @@
 <?php
 // $Id: attachment.module,v 1.10 2005/10/31 15:29:35 ccourtne Exp $
 
+function attachment_form_alter($form_id, &$form) {
+  $type = $form['type']['#value'];
+
+  switch ($form_id) {
+    // node edit form
+    case $type .'_node_form':
+      if (user_access('add attachments') && (variable_get('attachment_node_'. $type, 0) == 1)) {
+        $node = $form['#node'];
+        if (!isset($node->attachments)) {
+          $ret = attachment_load($node);
+          $node->attachments = $ret['attachments'];
+        }
+        $form['#attributes'] = array('enctype' => 'multipart/form-data');
+        $form = array_merge($form, attachment_form($node, $arg));
+      }
+      break;
+
+    // node settings form
+    case $type .'_node_settings':
+      $form['workflow']['attachment_node_'. $type] = array('#type'=>'radios', '#title'=>t('Attachments'), '#default_value'=>variable_get('attachment_node_'. $node->type, 0), '#options'=>array(0=>t('Disabled'), 1=>t('Enabled')));
+      break;
+  }
+}
+
 /**
  * Implementation of hook_nodeapi.
  */
 function attachment_nodeapi(&$node, $op, $arg = 0, $arg2 = 0) {
   switch ($op) {
-    case 'form':
-      if (user_access('add attachments') && (variable_get("attachment_node_$node->type", 0) == 1)) {
-        $form = attachment_form($node, $arg);
-        $form['#attributes'] = array('enctype' => 'multipart/form-data');
-      }
-      return $form;
-    case 'settings':
-      $form['attachment_node_'. $node->type] = array('#type'=>'radios', '#title'=>t('Attachments'), '#default_value'=>variable_get('attachment_node_'. $node->type, 0), '#options'=>array(0=>t('Disabled'), 1=>t('Enabled')));
-      return $form;
     case 'load':
       return attachment_load($node);
     case 'view':
@@ -63,7 +78,6 @@
       }
       return;
     case 'prepare':
-
       $node->attachments = $_POST['edit']['attachments'];
 
       if ($_POST['fileop'] == t('Add')) {
@@ -145,7 +159,7 @@
   $form['attachments'] = array('#type'=>'fieldset', '#title'=>t('Attachments'), '#tree'=>true, '#collapsible'=>true, '#weight'=>-8);
   $form['attachments']['#theme'] = 'attachment_form';
 
-  foreach ($node->attachments as $key=>$attachment) {
+  foreach ((array)$node->attachments as $key=>$attachment) {
     $fields = array('aid','fid','filename','size','working');
     foreach($fields as $field) {
       $form['attachments'][$key][$field] = array('#type'=>'hidden', '#value'=>$attachment[$field]);

