The current implementation of hook_tokens has a few issues:
- The keys in the associative return value do not contain the raw [type:token] strings from the original text, leaving parts of the raw strings in the processed text.
- It is set up to replace both "node" and "workflow" type tokens, although just offering the "workflow" type itself.
- If the node is being submitted, but the form data has not been saved to the database, yet, it replaces "old state" with the new state.
- If the node is being submitted, but the form data has not been saved to the database, yet, it incorrectly assumes the original author of the node to be the user, who last updated the node.
- It uses $node->user_mail to get the email address of the user, who last updated the node. I don't know where this actually comes from, but it doesn't seem to work on a standard Drupal 7 install.
Attached is a patch that should fix these issues.
Comment | File | Size | Author |
---|---|---|---|
#22 | 1418622-fix-workflow-tokens.patch | 11.27 KB | Dave Reid |
#21 | 1418622-fix-workflow-tokens.patch | 11.27 KB | Dave Reid |
#17 | workflow_correct_tokens.patch | 8.65 KB | fire-wolf |
#8 | workflow-incompatible-tokens-replacement-1418622-8.patch | 8.81 KB | B-Prod |
#1 | tokens-1418622-2.patch | 4.85 KB | Bastlynn |
Comments
Comment #1
Bastlynn CreditAttribution: Bastlynn commentedI rerolled your patch against the latest version of dev, since what you had set up wasn't applying. Looks good to me, but I would love to see someone testing done on this one before I commit it. Patch attached.
Comment #2
highermath CreditAttribution: highermath commentedWe successfully applied this patch to deal with the Functioning workflow, but getting workflow_tokens errors issue (http://drupal.org/node/1485816). From our perspective, it is RTBC, but I'll leave it to you to make that call.
Comment #3
audealexandre CreditAttribution: audealexandre commentedHi, I had the same issue ("Notice: Undefined index: node in workflow_tokens() (line 188 of /home/biblio/drupal-libnet/sites/all/modules/workflow/workflow.module)." appeared on the structure page of the content bound to the workflow), applied the patch in #1 successfully. Thank you.
Comment #4
ultimateboy CreditAttribution: ultimateboy commentedJust applied the patch and it fixed the issues I was having with workflow's tokens. Going to go ahead and mark rtbc.
Comment #5
shashanksingh CreditAttribution: shashanksingh commentedI have the same intermittent workflow_token() notices coming up.
Would this patch work?
How do I apply the patch?
Comment #6
loze CreditAttribution: loze commentedPatch in #1 worked for me as well.
Comment #7
berenddeboer CreditAttribution: berenddeboer commentedPatch doesn't apply against the latest dev version.
Comment #8
B-Prod CreditAttribution: B-Prod commentedHere is a patch against current DEV version, that is compatible with the
hook_tokens()
implementation expected in Drupal documentation: http://api.drupal.org/api/drupal/modules!system!system.api.php/function/....Comment #9
fire-wolf CreditAttribution: fire-wolf commentedIt works for me. Added patch manually. Before that patch tokens was not listed in 7.x-1.0 version too. Thanks.
Comment #10
sssmmm CreditAttribution: sssmmm commented#8 How should i apply this patch , on which version ..
I could not see the Token for Workflow module , it even break some other places it seems .. like Panels ..
I am using current Dev version of Workflow .. Which version of Rules you are using ? is it dependent ?
Any quick help would be appreciated ..
Comment #11
fire-wolf CreditAttribution: fire-wolf commentedHi!
I use Rules 2.0 and Workflow 1.0.
If you are not familiar with git, then simply open workflow.module, search for function workflow_tokens (what to search is always written in patch file) and open this patch in notepad. Then follow each row or block of rows - where row starts with "-" sign, you must delete that row in original module, but where row starts with "+" sign, you must add that row to module. Remove "+" signs after copying them to module. At the end don't forget to count braces closing ifs and cases - after last "case" there must be 5 closing braces }}}}}. That's all. If you use original module, I can send you updated version. But anyway it's better to know patching methods.
P.S. Always create backups of changeable files before such drastic changes!
Comment #12
sssmmm CreditAttribution: sssmmm commentedinfact i patched with patch command in freebsd .. but it did not work .. I will try editing on notepad.. Thanks for the tip ..
quick question , you edited the dev version of 7.x-1.x-dev or latest 7.x-1.0 ? (it seems 1.0 from you last reply but wanted to be sure)
did you used the patch #1 or #8 ?
reply to this question surely reduce my work a bit :)
Comment #13
fire-wolf CreditAttribution: fire-wolf commentedI edited latest 7.x-1.0 and use #8.
I did compare versions and there is no changes in workflow_tokens function. So I think it does not matter to which version you apply patch.
Comment #14
sssmmm CreditAttribution: sssmmm commentedFor some reason ..
I applied this patch via GIT , patch command and manual .. on both current stable and Dev version .. it do not show workflow option in the Rules page and Normal Taken replacement ..
I dont know what i am doing wrong ..
I need those workflow tokens to send the good mail .. but i am not able to do that after i upgrade to D7 last week ..
Comment #15
fire-wolf CreditAttribution: fire-wolf commentedDo you know that conditions and actions availability depends on the event you added?
Comment #16
sssmmm CreditAttribution: sssmmm commentedEvent or condition work as required under rules .. but Workflow token dont replace in the message on the page and in the mail as they dont exist or show me under replacement pattern when i try to send HTML mail or message to user on the page .. they just sent as token name only .. which is no go ..
Comment #17
fire-wolf CreditAttribution: fire-wolf commentedSome people ask for patch for 7.x-1.0 version.
Comment #18
waltercat CreditAttribution: waltercat commentedI have tried doing this for 7.x -1.0 and the dev version and nothing is showing up still. Does this patch just help the tokens show up or does it actually insert the functionality into the actions? Does anyone have the D7 tokens for these D6 versions? I can't seem to find them anywhere.
Comment #19
NancyDruSee also #1874400: Workflow Token Works in Message Body but Not Subject for Emails in Rules
Comment #20
NancyDruI would really, really appreciate someone re-rolling this for the current dev, which has some changes in this area. See #1891374: Tokens issues
Comment #21
Dave ReidTook a stab at this with the current dev. This needs testing before commit.
Comment #22
Dave ReidThis has actually been tested and all tokens work except for [node:workflow-current-state-log-entry] which is unrelated to this issue. I'll file a new ticket for that issue.
Comment #23
NancyDruThanks so much, Dave. Committed to -dev.
Comment #24
davidwhthomas CreditAttribution: davidwhthomas commentedJust a note, but I tried -dev with the token support feature added.
The tokens showed up in Rules, however the new and old states were incorrect.
Event: Workflow state updated
Current state: New
Old state: New
That came through in an email notification sent when the workflow state was updated.
Although I updated and set it to "Finished" the token showed current state as "New"
Comment #25
NancyDruI'm getting them backwards on a state change rule. However, a "content is viewed" rule produces the correct information.
Comment #26
NancyDruI committed a fix for this.