? .DS_Store
? 000000.storm.modify_task_with_comment.patch
? example.patch
Index: stormtask/stormtask.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/storm/stormtask/stormtask.module,v
retrieving revision 1.6.4.57
diff -u -p -r1.6.4.57 stormtask.module
--- stormtask/stormtask.module	19 Dec 2009 15:06:04 -0000	1.6.4.57
+++ stormtask/stormtask.module	30 Dec 2009 22:23:39 -0000
@@ -931,3 +931,73 @@ function stormtask_views_api() {
     'path' => drupal_get_path('module', 'stormtask'),
   );
 }
+
+/**
+ * Implementation of hook_form_FORM_ID_alter() for comment form.
+ *
+ * This only does anything if a comment is being made on a node of type
+ * stormtask *and* the current user has access to modify the node.
+ * If these conditions are met, some fields are added to allow the commenter
+ * to modify some of the node's attributes. On submission, the node is saved if
+ * any of these attributes have been changed, the node is modified accordingly.
+ * Note that this method does not take note
+ */
+function stormtask_form_comment_form_alter(&$form, $form_state) {
+    // we will need to load the node to check for its type
+  $node = node_load($form['nid']['#value']);
+
+    // only alter this form if the type is stormtask and we have access to
+    // it. Note that stormtask_access() works with a node id or a node object.
+  if ($node->type == 'stormtask' && stormtask_access('update', $node)) {
+      // if we are saving this comment, save a new version of the node if necessary.
+    if ($form_state['post']['op'] == 'Save') {
+        // keep note of changes. We will add this to the revision log.
+      $changes = array();
+        // change the current node with current attribute (only if changes
+        // have been made)
+      foreach (array('taskcategory', 'taskstatus', 'taskpriority') as $attribute) {
+        if ($node->$attribute != $form_state['post'][$attribute]) {
+          $changes[] = $attribute . ': ' . $node->$attribute . ' » ' . $form_state['post'][$attribute];
+          $node->$attribute = $form_state['post'][$attribute];
+        }
+      }
+        // if changes have been made, save the new version of the node as a
+        // revision of we have that privilege and set a watchdog notice.
+      if (count($changes)) {
+        $node->revision = 'node/' . $form['nid']['#value'] . ' ' . t('modified via a comment') . ': ' . implode('; ', $changes);
+        watchdog('stormtask', $node->revision);
+        node_save($node);
+      }
+
+      // if we are not saving this comment, modify the comment form to
+      // allow the user to change certain attributes of the node at the
+      // same time as leaving a comment.
+    }
+    else {
+      $taskcategory_list = stormattribute_attributes_bydomain('Task category');
+      $form['group2']['#weight'] = -1;
+      $form['group2']['taskcategory'] = array(
+        '#type' => 'select',
+        '#title' => t('Modify category'),
+        '#default_value' => $node->taskcategory,
+        '#options' => $taskcategory_list['values'],
+      );
+
+      $taskstatus_list = stormattribute_attributes_bydomain('Task status');
+      $form['group2']['taskstatus'] = array(
+        '#type' => 'select',
+        '#title' => t('Modify status'),
+        '#default_value' => $node->taskstatus,
+        '#options' => $taskstatus_list['values'],
+      );
+
+      $taskpriority_list = stormattribute_attributes_bydomain('Task priority');
+      $form['group2']['taskpriority'] = array(
+        '#type' => 'select',
+        '#title' => t('Modify priority'),
+        '#default_value' => $node->taskpriority,
+        '#options' => $taskpriority_list['values'],
+      );
+    }
+  } // end if ($node->type == 'stormtask' && stormtask_access('update', $node))
+}
\ No newline at end of file
