? comment.inc.save
Index: comment.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/includes/comment.inc,v
retrieving revision 1.155
diff -u -p -r1.155 comment.inc
--- comment.inc	23 Sep 2009 00:27:05 -0000	1.155
+++ comment.inc	20 Dec 2009 12:01:27 -0000
@@ -46,6 +46,25 @@ function project_issue_comment(&$arg, $o
 
       if (isset($id)) {
         $rid = isset($arg['project_info']['rid']) ? $arg['project_info']['rid'] : 0;
+        // If the comment does not change something then we want to keep the
+        // current value not what was present when the original form was
+        // created aka avoid crossposting.
+        foreach ($arg['project_info']['originals'] as $key => $original_value) {
+          // Let's find where in argument the posted value is...
+          if (in_array($key, array('category', 'priority', 'sid', 'title'))) {
+            $posted_value = &$arg[$key];
+          }
+          else {
+            $posted_value = &$arg['project_info'][$key];
+          }
+          // If the user did not intend to change the value but it was changed
+          // since then use that.
+          if ($posted_value == $original_value && $posted_value != $old_data->$key) {
+            $posted_value = $old_data->$key;
+          }
+          unset($posted_value);
+        }
+    
         db_query("INSERT INTO {project_issue_comments} (nid, cid, pid, rid, component, category, priority, assigned, sid, title, timestamp, comment_number) VALUES (%d, %d, %d, %d, '%s', '%s', %d, %d, %d, '%s', %d, %d)", $arg['nid'], $arg['cid'], $arg['project_info']['pid'], $rid, $arg['project_info']['component'], $arg['category'], $arg['priority'], $arg['project_info']['assigned'], $arg['sid'], $arg['title'], $arg['timestamp'], $id);
         db_query("UPDATE {comments} SET subject = '%s' WHERE cid = %d", "#$id", $arg['cid']);
         project_issue_update_by_comment($arg, 'insert');
@@ -283,6 +302,15 @@ function project_issue_form_comment_form
   // Restructure the UI to de-emphasize the original project form inputs.
   $form['original_issue']['project_info'] = $form['project_info'];
   $form['original_issue']['issue_info'] = $form['issue_info'];
+  // We need a bunch of hiddens to record the current state. We can't use #type
+  // value because otherwise these would contain the state of the issue at
+  // submission type. Caching the form would allow for #type value but I am not
+  // keen on trying to cache the comment form. Also, there is no harm in
+  // hiddens -- although the user can tamper them but we do not use it for
+  // anything but comparison.
+  $form['original_issue']['project_info']['originals'] =  _project_issue_node_form_values($node, 'hidden', '#default_value');
+  $form['original_issue']['project_info']['originals']['title'] = array('#type' => 'hidden', '#default_value' => $node->title);
+
   unset($form['project_info'], $form['issue_info']);
   unset($form['issue_details'], $form['project_help']);
   drupal_add_js(drupal_get_path('module', 'project_issue') .'/project_issue.js');
Index: issue_node_form.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/includes/issue_node_form.inc,v
retrieving revision 1.5
diff -u -p -r1.5 issue_node_form.inc
--- issue_node_form.inc	8 Oct 2009 23:36:16 -0000	1.5
+++ issue_node_form.inc	20 Dec 2009 12:01:27 -0000
@@ -319,39 +319,8 @@ function _project_issue_form($node, $for
     // If we're not allowing issue metadata changes, add all of these values
     // into the form so they show up in the $node->project_issue array during
     // validation and submit, so we're consistent with where they live.
-    $form['project_issue'] = array('#tree' => TRUE);
-    $form['project_issue']['pid'] = array(
-      '#type' => 'value',
-      '#value' => $node->project_issue['pid'],
-    );
-    if (isset($node->project_issue['rid'])) {
-      $form['project_issue']['rid'] = array(
-        '#type' => 'value',
-        '#value' => $node->project_issue['rid'],
-      );
-    }
-    $form['project_issue']['component'] = array(
-      '#type' => 'value',
-      '#value' => $node->project_issue['component'],
-    );
-    $form['project_issue']['category'] = array(
-      '#type' => 'value',
-      '#value' => $node->project_issue['category'],
-    );
-    $form['project_issue']['priority'] = array(
-      '#type' => 'value',
-      '#value' => $node->project_issue['priority'],
-    );
-    $form['project_issue']['assigned'] = array(
-      '#type' => 'value',
-      '#value' => $node->project_issue['assigned'],
-    );
-    $form['project_issue']['sid'] = array(
-      '#type' => 'value',
-      '#value' => $node->project_issue['sid'],
-    );
+    $form['project_issue'] = _project_issue_node_form_values($node);
   }
-
   $form['issue_details'] = array(
     '#type' => 'fieldset',
     '#title' => t('Issue details'),
@@ -399,6 +368,55 @@ function _project_issue_form($node, $for
 }
 
 /**
+ * Internal helper for pulling project issue properties out of a node.
+ *
+ * @param $node
+ *   The project issue node.
+ * @param $type
+ *   What kind of form element to use, defaults to value.
+ * @param $key
+ *   Which form property to put the project issue properties into.
+ *
+ * @return
+ *   A bunch of form elements containing pid, rid, component, category,
+ *   priority, assigned, sid.
+ */
+function _project_issue_node_form_values($node, $type = 'value', $key = '#value') {
+  $return = array('#tree' => TRUE);
+  $return['pid'] = array(
+    '#type' => $type,
+    $key => $node->project_issue['pid'],
+  );
+  if (isset($node->project_issue['rid'])) {
+    $return['rid'] = array(
+      '#type' => $type,
+      $key => $node->project_issue['rid'],
+    );
+  }
+  $return['component'] = array(
+    '#type' => $type,
+    $key => $node->project_issue['component'],
+  );
+  $return['category'] = array(
+    '#type' => $type,
+    $key => $node->project_issue['category'],
+  );
+  $return['priority'] = array(
+    '#type' => $type,
+    $key => $node->project_issue['priority'],
+  );
+  $return['assigned'] = array(
+    '#type' => $type,
+    $key => $node->project_issue['assigned'],
+  );
+  $return['sid'] = array(
+    '#type' => $type,
+    $key => $node->project_issue['sid'],
+  );
+  return $return;
+}
+
+/**
  * Private helper to implement hook_validate().
  *
  * Ensures that the issue node form has valid values for all required fields.
