? workflow-by-node.patch
Index: workflow.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/workflow/workflow.module,v
retrieving revision 1.83
diff -u -p -r1.83 workflow.module
--- workflow.module	1 Jan 2009 21:09:16 -0000	1.83
+++ workflow.module	27 May 2009 22:45:57 -0000
@@ -112,7 +112,7 @@ function workflow_menu() {
  */
 function workflow_node_tab_access($node = NULL) {
   global $user;
-  $wid = workflow_get_workflow_for_type($node->type);
+  $wid = workflow_get_workflow_for_node($node);
   if ($wid === FALSE) {
     // No workflow associated with this node type.
     return FALSE;
@@ -223,7 +223,7 @@ function workflow_nodeapi(&$node, $op, $
       // Note no break; fall through to 'update' case.
     case 'update':
       // Do nothing if there is no workflow for this node type.
-      $wid = workflow_get_workflow_for_type($node->type);
+      $wid = workflow_get_workflow_for_node($node);
       if (!$wid) {
         break;
       }
@@ -423,7 +423,7 @@ function workflow_form_alter(&$form, $fo
       $node = node_load($form['nid']['#value']);
     }
     $choices = workflow_field_choices($node);
-    $wid = workflow_get_workflow_for_type($node->type);
+    $wid = workflow_get_workflow_for_node($node);
     $states = workflow_get_states($wid);
     // If this is a preview, the current state should come from
     // the form values, not the node, as the user may have changed
@@ -673,7 +673,7 @@ function workflow_select_given_state_act
  */
 function workflow_field_choices($node) {
   global $user;
-  $wid = workflow_get_workflow_for_type($node->type);
+  $wid = workflow_get_workflow_for_node($node);
   if (!$wid) {
     // No workflow for this type.
     return array();
@@ -712,7 +712,7 @@ function workflow_node_current_state($no
 
   if (!$sid) {
     // No current state. Use creation state.
-    $wid = workflow_get_workflow_for_type($node->type);
+    $wid = workflow_get_workflow_for_node($node);
     $sid = _workflow_creation_state($wid);
   }
   return $sid;
@@ -941,6 +941,23 @@ function workflow_get_name($wid) {
 }
 
 /**
+ * Get ID of a workflow for a node.
+ *
+ * @param $node
+ *   A node object.
+ * @return int
+ *   The ID of the workflow or FALSE if no workflow is mapped to this node.
+ */
+function workflow_get_workflow_for_node($node) {
+  if ($wid = module_invoke_all('workflow_node_map')) {
+    return array_pop($wid);
+  }
+  else {
+    return workflow_get_workflow_for_type($node->type);
+  }
+}
+
+/**
  * Get ID of a workflow for a node type.
  *
  * @param $type
@@ -1453,7 +1470,7 @@ function workflow_token_values($type, $o
     case 'workflow':
       $node = (object)$object;
 
-      if ($wid = workflow_get_workflow_for_type($node->type)) {
+      if ($wid = workflow_get_workflow_for_node($node)) {
         $values['workflow-name'] = workflow_get_name($wid);
         $states = workflow_get_states($wid);
       }
Index: workflow.pages.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/workflow/workflow.pages.inc,v
retrieving revision 1.2
diff -u -p -r1.2 workflow.pages.inc
--- workflow.pages.inc	29 Oct 2008 03:13:55 -0000	1.2
+++ workflow.pages.inc	27 May 2009 22:45:57 -0000
@@ -11,7 +11,7 @@
  */
 function workflow_tab_page($node = NULL) {
   drupal_set_title(check_plain($node->title));
-  $wid = workflow_get_workflow_for_type($node->type);
+  $wid = workflow_get_workflow_for_node($node);
   $states_per_page = variable_get('workflow_states_per_page', 20);
   $result = db_query("SELECT sid, state FROM {workflow_states} WHERE status = 1 ORDER BY sid");
   while ($data = db_fetch_object($result)) {
@@ -121,7 +121,7 @@ function workflow_tab_form($form_state, 
   $min = $states[$current] == t('(creation)') ? 1 : 2;
   // Only build form if user has possible target state(s).
   if (count($choices) >= $min) {
-    $wid = workflow_get_workflow_for_type($node->type);
+    $wid = workflow_get_workflow_for_node($node);
     $workflow = workflow_load($wid);
     $form['#wf'] = $workflow;
     $name = check_plain($workflow->name);
