[PATCH] How to set workflow comment during automated stated transition with Workflow Rules Set State Action on a Drupal 7 site
The Workflow module in Drupal, as part of its Rules module integration, allows you various rules based actions, of which one commonly used one is the action to change the workflow state from state to another. But that one doesn't have an option to set the comment for that state change, which can be quite useful when you see the Workflow History of a node.
I have created a patch for the latest dev version (7.x-1.0+20-dev) of the Workflow module to help you with that:
diff --git a/workflow_rules/workflow_rules.rules.inc b/workflow_rules/workflow_rules.rules.inc
index be9a8b9..21e3b45 100644
--- a/workflow_rules/workflow_rules.rules.inc
+++ b/workflow_rules/workflow_rules.rules.inc
@@ -94,6 +94,12 @@ function workflow_rules_rules_action_info() {
'options list' => '_workflow_rules_action_select',
'description' => t('The workflow state to set (select only one).'),
),
+ 'workflow_comment' => array(
+ 'type' => 'text',
+ 'label' => t('Workflow Comment'),
+ 'description' => t('The workflow comment to set.'),
+ 'optional' => TRUE,
+ ),
),
),
);
@@ -158,5 +164,9 @@ function workflow_check_state($node, $states) {
*/
function workflow_rules_set_state($node, $states) {
$sid = array_pop($states); // Select the last state on the list.
+ if ($comment) {
+ $node->workflow_comment = $comment;
+ }
workflow_transition($node, $sid);
+ unset($node->workflow_comment);
}
This patch gives you an additional text area to the action definition form, for you to enter the workflow comment that has to be added while executing the state change. It also does the job of adding this comment during the state transition.
Attachment(the patch file): http://drupal.org/files/set_workflow_comment_with_workflow_rules_set_sta...
This has also been added to the Drupal page here: http://drupal.org/node/1783854
- 78552 reads
Add new comment