Typical scenario:
- -
A document/node must be moved from 'in progress/draft' to 'edited draft' such that the copy editing team can check grammar and stuff. The 'editor' chooses the 'edited draft' state and an automated email gets sent out alerting a user with role of 'copy editing' to check the copy.
If the given copy editor is too busy, then they assign it to another copy editor.
- -
What's needed here is a system of assigning a user to be responsible for the document in a given state. I believe it's possible to show an appropriate user list based on the state clicked when changing the workflow state.
Considering I can choose what roles can edit a document in a given state then it must be possible to show an applicable user list based on role.
Bonus: Instead of always notifying the same person based on a state transition, we could now notify just the person assigned.
Note that this issue is not a duplicate of http://drupal.org/node/841554 nor http://drupal.org/node/362105 as these things drifted off in some really weird direction.
Also note that a simple solution would involve using the User References module to make a user term list and some really hacky javascript for validation but I don't want to do that... it doesn't feel right.
Comments
Comment #1
dynamicdan commentedOk.. seems kind of quiet here..
My Progress:
Easiest way for me to save the userID would be to hack it into the comment field but I think it should be better than that. I haven't worked much with saving to drupal but I assume there is some easy hook/function. I don't want to alter workflow too much so I will see how easy it is to do the right way. Otherwise I'll do it the quick and dirty way that could be improved later.
Thoughts and advice appreciated.
Existing code below.. BTW, is there a workflow_node_form_alter? If I use the hook workflow_form_alter then I won't have all the vars I want ($form, $form_state, $name, $name, $current, $choices, $timestamp, $comment).
Comment #2
dynamicdan commentedComment #3
Encarte commentedIMHO, you may be trying to get from Australia to New Zeeland via London, which may work, but demands a lot of effort and may not develop transportation systems around Oceania.
If I got it right, what you need is a list of the users that, on a given workflow state, have a workflow permission (access permission or transition permission). You also need some users to select other from that list and to trigger an email when that selection happens.
You can create a CCK field on your node that automatically makes such a list and that lets users chose from it. To get only the desired users on the list get http://drupal.org/project/entityreference and http://drupal.org/project/entityreference_view_widget . With them you can make the list with a view, using the exposed filters (formerly known as arguments). The exposed filters let you take information from a context (e. g. the node that is being displayed and its workflow state) and use it to make a list. I don't think there is an exposed filter for pulling out users with some workflow permission, but creating one would probably be a piece of cake compared to what you're trying to do here.
So, this would be a completely no-hack solution, you would learn how to use some essential modules (no, you can't really build serious Drupal sites without the ones I mentioned, let alone building press sites) and you would only have to code (not hack) a new exposed filter for workflow permissions (and, since you like to pay attention to details, you would probably find and crush some bugs on your way).
To trigger an email when a user is selected (and not only when the state changes) you can use the rules module.
Drupal needs new devs like you. Be nice to people and you'll find awesome friends in here. I hope this message was useful.
Comment #4
dynamicdan commentedThanks Encarte.
You raise some good points... I have however just completed my (hacky) implementation.
The catch with using a view to show a user list is that one should not reload the page or use AJAX (too slow) to show an applicable list. That suggestion would work, but not in a user friendly way from what I understand.
I've realised now that there are some critical processes that need to be taken into account in assigning users...
* if one were to continue to maintain this module with the initial dev mind set, one could use a generic system like tokens to flag content upon transitions. Eg, [uid:109] or [mark:priority] in comments.
Tools I used included: the user reference plugin for showing a list of users, improved workflow summary view to filter by users, a custom module to keep the code separate and hook into transitions and send emails, CSS for hiding certain elements (I felt that putting workflow controls on the edit screen was system overload for the user), some clever JS jQuery.
I could have used rules more but at the time there was a bug of which is now patched I believe. I would've however had a hard time customising emails and their conditions for sending.
In total I have < 250 lines of code + ~70 lines of JS to do everything. If I had more experience with the workflow module and Drupal I could have cut probably >25% of the code.
I can post the code if anyone is interested. If I have time (and if it's possible) then I'd probably use the token system for variable matching instead of regex matching on "Assigned to user: james_smith (Editor, QA Review) (id:201)". Don't know much about enabling tokens though :(
Could tokens used in comments be exposed for views?
Comment #5
dhakshinait commentedCan you post your code please?.I need above mentioned requirement for my project and i am working with version 6.Your code will help me to create that same functionality in version 6 too..
Comment #6
dynamicdan commentedSeeing as how I usually take more than I give, here's the code:
https://dl.dropbox.com/u/259788/drupal/workflow_addons.zip
Notes:
1)
2)
In exchange, I'd be more than grateful if you could provide some feedback and tips on how to improve my code. I'm very keen to release it as a proper stand alone module. I would especially like a way to avoid hacking the workflow module to get my changes to work.
BTW, this code has been used in a production environment and is working well.
Comment #7
nancydruI can't really say I understand this but you may want to see if Rules can do this
Comment #8
nancydruI will be committing this change for you, so you can do a proper form_alter()
Your Dropbox seems to be gone, so I can't see the extra function for a default comment.
Comment #9
nancydruI'll also give you a chance to change the comment in workflow_execute_transition():
So, you can implement a hook_workflow_comment_alter() if you so desire. You may not alter the contents of the $context array, but have at it on the comment text.
Comment #10
nancydruNo further updates from posters.
Comment #11
johnvITMT, in version 7.x.2.x, a new hook_..._alter() is introduced, where you can programmatically change the permitted transitions based upon your own criteria.
But in this case, you'd like to add the 'reviewer' to the transition, not the node itself. Let's discuss that in #2262915: [META] Allow changing of Workflow Widget before displaying it.