Here's a patch that adds an option to set milestone id to unfuddle_api's admin screen. Update of unfuddle's screen is done by hook_menu_alter.

Functionality:
Now, you can set up milestone id in unfuddle_api's admin screen. When the request for unfuddle will be created, now the module checks if the milestone id is set and in case it is a number > 0 a tag [milestone id] is added to xml of request.

Patch

  • File unfuddle_feedback.install - you can now use the new file. Setting of unfuddle_api_milestone variable is added.
  • File unfuddle_feedback.module - Please append the 3 functions from attachment to original module's file.

Comments

jody lynn’s picture

Status: Active » Needs work

Instead of re-creating the settings form with hook_menu_alter, you need to use hook_form_alter to add a new field to the form. This way other modules can also alter the form.

Don't use the alter hook for adding the new milestone field to the ticket - just add it in where the other fields are added in unfuddle_feedback. Alter hooks are for additional modules to use not usually the module that invokes it.

In the install file, that update function is for sites that used to be on an old version of unfuddle_feedback. No longer relevant for new changes. To delete the new variable you want to put a variable_del in a hook_uninstall in the install file.

Get a copy of the module from git using the 'Version Control' tab of the project page and copy over your changes. Then you can generate a real patch with

git diff > 1864814.patch

barancekk’s picture

StatusFileSize
new2.25 KB

Thank you very much for comments. I created hook_form_alter(), hook_uninstall(). Real patch file is uploaded in attachment.

jody lynn’s picture

Name the variable unfuddle_feedback_milestone so that it's namespaced to the module that defines it.

To get only the changes you want, and not irrelevant ones, you can do git add -p and answer y/n to each bit and then do git diff --staged to get a diff of just what you added.

+++ b/unfuddle_feedback.infoundefined
@@ -3,3 +3,10 @@ description = Provides Unfuddle API integration for feedback module.
+
+; Information added by drupal.org packaging script on 2011-11-12
+version = "7.x-1.x-dev"
+core = "7.x"
+project = "unfuddle_feedback"
+datestamp = "1321059390"

This stuff is added in by drupal.org's packaging if you don't get the code from git. We don't want to add this into the codebase, so delete this stuff.

+++ b/unfuddle_feedback.installundefined
+++ b/unfuddle_feedback.installundefined
@@ -22,4 +22,11 @@ function unfuddle_feedback_update_6000() {

@@ -22,4 +22,11 @@ function unfuddle_feedback_update_6000() {
     }
   }
   return $ret;
-}
\ No newline at end of file
+}

This is just some kind of whitespace change we don't want.

+++ b/unfuddle_feedback.moduleundefined
@@ -37,9 +37,28 @@ function unfuddle_feedback_post_ticket($entry) {
+  // If milestone id is set and > 0 we add it to fields.
+  if (($milestone_id = variable_get('unfuddle_api_milestone', 0)) > 0) {
+    $fields['milestone-id'] = $milestone_id;
+  }
+
   drupal_alter('unfuddle_feedback_subject', $subject, $entry);
   drupal_alter('unfuddle_feedback_description', $description, $entry);
   drupal_alter('unfuddle_feedback_fields', $fields, $entry);
   return $unfuddle->createTicket($subject, $description, $fields);
 }
 
+/**
+ * Implements hook_form_alter().
+ */
+function unfuddle_feedback_form_alter(&$form, &$form_state, $form_id) {
+  if ($form_id == 'unfuddle_api_admin_settings') {
+    $form['unfuddle_api_milestone'] = array(
+      '#type' => 'textfield',
+      '#title' => t("Unfuddle milestone ID"),
+      '#description' => t('The integer ID of the milestone, e.g. 12345. Find this in your project URL.'),
+      '#default_value' => variable_get('unfuddle_api_milestone'),
+    );
+  }
+}

You don't need the ">0" as 0 will evaluate to false anyway.

+++ b/unfuddle_feedback.moduleundefined
@@ -37,9 +37,28 @@ function unfuddle_feedback_post_ticket($entry) {
+function unfuddle_feedback_form_alter(&$form, &$form_state, $form_id) {

You should instead implement hook_form_FORM_ID_alter and condense these two lines

barancekk’s picture

StatusFileSize
new1.75 KB

Thanks a lot for comments. Everything is updated in new patch in attachment. I used the > 0 condition in (($milestone_id = variable_get('unfuddle_api_milestone', 0)) > 0) to tell php to get only positive numbers and not string but the decision of format for assignee should be on the web user that sets it.

barancekk’s picture

StatusFileSize
new1.75 KB

You can ignore the patch version in comment 4 and use this one. Thanks

dags’s picture

This should probably be moved to the Unfuddle API project. Also, if an incorrect Milestone number is given, it will create a ticket without any milestone. It might good to add some validation code to check the milestone number and let the user know if they've entered an invalid number. Or use UnfuddleAPI's getMilestones() method in combination with some AJAX to return and populate the Milestone field.

jody lynn’s picture

Status: Needs work » Fixed

I committed this to 7.x-1.x

I am fine with the milestone setting being in unfuddle_feedback where it's needed. If unfuddle_api users want more settings and that's one of them we can move the setting over there in the future.

Also not concerned about validating the milestone since adding tickets in no milestone is what has always happened by default.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.