? 708318-a.patch
? 708318.patch
? tests
Index: decisions.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/decisions/decisions.module,v
retrieving revision 1.227
diff -u -p -r1.227 decisions.module
--- decisions.module	4 Feb 2010 17:32:54 -0000	1.227
+++ decisions.module	9 Feb 2010 01:49:22 -0000
@@ -524,54 +524,6 @@ function decisions_view_results(&$node, 
 }
 
 /**
- * View the voting form.
- *
- * This calls a function decisions_vote_$mode, where $mode is defined
- * in the node. If the function does not exist, a watchdog error is
- * raised and the error is reported using drupal_set_message().
- *
- * This also takes care of registering new votes, if the vote button
- * has been pressed.
- */
-function decisions_voting_form($form, &$node, $teaser = FALSE, $page = FALSE) {
-  $mode = _decisions_get_mode($node);
-  if (function_exists("{$mode}_decisions_voting_form")) {
-    return call_user_func("{$mode}_decisions_voting_form", $node, $teaser, $page);
-  }
-  else {
-    _decisions_panic_on_mode($mode, __FUNCTION__);
-  }
-}
-
-function decisions_voting_form_submit($form, &$form_state) {
-  $node = node_load($form_state['values']['nid']);
-  decisions_vote($node, $form_state['values']);
-  drupal_set_message(t('Your vote was registered.'));
-  // Transferring makes the results tab display correctly
-  drupal_goto('node/'. $node->nid);
-}
-
-/**
- * Validate vote form submission
- *
- * This will call a hook named decisions_vote_validate_$mode and
- * return its value. hooks should check $POST to see if the vote data
- * submitted is valid and use form_set_error() if the form has invalid
- * data.
- *
- * @returns boolean true if form has valid data or if no hook is
- * defined in mode
- */
-function decisions_voting_form_validate($form, &$form_state) {
-  $node = node_load($form_state['values']['nid']);
-  $mode = _decisions_get_mode($node);
-  if (function_exists("{$mode}_decisions_vote_validate")) {
-    return call_user_func("{$mode}_decisions_vote_validate", $node, $form_state['values']);
-  }
-  return TRUE;
-}
-
-/**
  * Record a vote on the node.
  *
  * This calls the appropriate vote recording function, depending on
@@ -1342,7 +1294,8 @@ function decisions_view(&$node, $teaser 
 
   if (arg(2) != 'results' && _decisions_can_vote($node)) {
     // User hasn't voted and we're not on the results tab
-    $node->content['decisions']['form']['#value'] = drupal_get_form('decisions_voting_form', $node, $teaser, $page);
+    $mode = _decisions_get_mode($node);
+    $node->content['decisions']['form']['#value'] = drupal_get_form('decisions_' . $mode . '_voting_form', $node, $teaser, $page);
     $node->content['decisions']['list']['#value'] = theme('decisions_view_header', $node, $teaser);
   }
   elseif (_decisions_can_view_results($node)) {
Index: modes/ranking.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/decisions/modes/ranking.module,v
retrieving revision 1.25
diff -u -p -r1.25 ranking.module
--- modes/ranking.module	4 Feb 2010 17:32:54 -0000	1.25
+++ modes/ranking.module	9 Feb 2010 01:49:22 -0000
@@ -62,15 +62,19 @@ function ranking_decisions_algorithms() 
 }
 
 /**
- * Implementation of the decisions_voting_hook_form() hook for the runoff module.
+ * Implementation of the decisions_hook_voting_form() hook for the runoff module.
  *
  * This displays a textfield per choice, that should be filled with a
  * ranking.
  */
-function ranking_decisions_voting_form(&$node, $teaser, $page) {
+function decisions_ranking_voting_form($form_state, &$node, $teaser, $page) {
 
   $weight = 0;
   $form = array();
+  $form['node'] = array(
+    '#type' => 'value',
+    '#value' => $node,
+  );
 
   if ($node->choice) {
     $list = array();
@@ -269,9 +273,10 @@ function ranking_decisions_format_votes(
  *
  * This takes care of registering the vote in runoff nodes.
  */
-function ranking_decisions_vote($node, $form_values) {
+function decisions_ranking_voting_form_submit($form, &$form_state) {
   $votes = array();
-  foreach ($form_values['choice'] as $choice => $rank) {
+  $node = $form_state['values']['node'];
+  foreach ($form_state['values']['choice'] as $choice => $rank) {
     // A zero value indicates they didn't rank that choice
     if ($rank != 0) {
       $vote = array('value' => $rank,
@@ -287,14 +292,13 @@ function ranking_decisions_vote($node, $
 }
 
 /**
- * implementation of the vote validation hook for the runoff module.
- *
  * This checks if the submitted values are within range, if they are
  * not empty, and if they are not repeated.
  *
  * @returns boolean false on invalid forms, true otherwise.
  */
-function ranking_decisions_vote_validate($node, $form_values) {
+function decisions_ranking_voting_form_validate($form, &$form_state) {
+  $node = $form_state['values']['node'];
   $ok = TRUE;
   // array used to check which values are set
   $setvalues = array();
@@ -303,10 +307,10 @@ function ranking_decisions_vote_validate
   foreach ($node->choice as $key => $choice) {
 
     // count the number of choices that are ranked
-    if (!empty($form_values['choice'][$key])) {
+    if (!empty($form_state['values']['choice'][$key])) {
       $numchoices++;
     }
-    $intvalue = intval($form_values['choice'][$key]);
+    $intvalue = intval($form_state['values']['choice'][$key]);
     // mark this value as seen
     if (!array_key_exists($intvalue, $setvalues)) {
       $setvalues[$intvalue] = 1;
Index: modes/selection.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/decisions/modes/selection.module,v
retrieving revision 1.17
diff -u -p -r1.17 selection.module
--- modes/selection.module	4 Feb 2010 17:32:54 -0000	1.17
+++ modes/selection.module	9 Feb 2010 01:49:23 -0000
@@ -47,20 +47,22 @@ function selection_decisions_algorithms(
 }
 
 /**
- * Implementation of the decisions_voting_hook_form() hook for the selection module.
- *
- * This creates a list of choices to allow the user to vote on choices.
+ * Implementation of decisions_hook_voting_form.
+ * Presents a list of choices for the user to vote on.
  */
-function selection_decisions_voting_form(&$node, $teaser, $page) {
+function decisions_selection_voting_form($form_state, &$node, $teaser, $page) {
+  $form['node'] = array(
+    '#type' => 'value',
+    '#value' => $node,
+  );
+
   if ($node->choice) {
     $list = array();
-
     // Put options in random order if randomize option
     // selected on node create/edit form.
     if ($node->randomize) {
       $node->choice = _decisions_randomize_options($node->choice, $node->choices);
     }
-
     if ($node->maxchoices == 1) {
       // plurality voting
       foreach ($node->choice as $i => $choice) {
@@ -98,7 +100,6 @@ function selection_decisions_voting_form
     '#type' => 'submit',
     '#value' => t('Vote'),
   );
-  $form['#action'] = url('node/'. $node->nid);
   return $form;
 }
 
@@ -173,17 +174,16 @@ function selection_decisions_format_vote
 }
 
 /**
- * implementation of the submit() hook
- *
- * registers the vote as a key for this node using votingapi_set_vote()
+ * Registers the vote as a key for this node using votingapi_set_vote()
  */
-function selection_decisions_vote($node, $form_values) {
+function decisions_selection_voting_form_submit($form, &$form_state) {
+  $node = $form_state['values']['node'];
   $votes = array();
   if ($node->maxchoices == 1) {
     // plurality voting
     $vote = array(
       'value' => 1,
-      'tag' => $form_values['choice'],
+      'tag' => $form_state['values']['choice'],
       'value_type' => 'option',
       'content_type' => 'decisions',
       'content_id' => $node->nid,
@@ -193,7 +193,7 @@ function selection_decisions_vote($node,
   else {
     // approval voting
     foreach ($node->choice as $key => $choice) {
-      if (isset($form_values['choice'][$key]) && $form_values['choice'][$key]) {
+      if (isset($form_state['values']['choice'][$key]) && $form_state['values']['choice'][$key]) {
         $vote = array(
           'value' => 1,
           'value_type' => 'option',
@@ -215,11 +215,12 @@ function selection_decisions_vote($node,
  *
  * @returns boolean true if the form is valid
  */
-function selection_decisions_vote_validate($node, $form_values) {
+function decisions_selection_voting_form_validate($form, &$form_state) {
+  $node = $form_state['values']['node'];
   $ok = TRUE;
   if ($node->maxchoices == 1) {
     // plurality voting
-    if (!array_key_exists($form_values['choice'], $node->choice)) {
+    if (!array_key_exists($form_state['values']['choice'], $node->choice)) {
       form_set_error('choice', 'At least one choice must be selected.');
       $ok = FALSE;
     }
@@ -238,7 +239,7 @@ function selection_decisions_vote_valida
       //}
 
       // see if the box is checked
-      if (!empty($form_values['choice'][$key])) {
+      if (!empty($form_state['values']['choice'][$key])) {
         $numchoices++;
       }
     }
