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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Bastlynn’s picture

Status: Active » Needs review
FileSize
4.85 KB

I 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.

highermath’s picture

We 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.

audealexandre’s picture

Version: 7.x-1.x-dev » 7.x-1.0

Hi, 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.

ultimateboy’s picture

Version: 7.x-1.0 » 7.x-1.x-dev
Status: Needs review » Reviewed & tested by the community

Just applied the patch and it fixed the issues I was having with workflow's tokens. Going to go ahead and mark rtbc.

shashanksingh’s picture

I have the same intermittent workflow_token() notices coming up.
Would this patch work?
How do I apply the patch?

loze’s picture

Patch in #1 worked for me as well.

berenddeboer’s picture

Status: Reviewed & tested by the community » Needs work

Patch doesn't apply against the latest dev version.

B-Prod’s picture

Title: Token replacement partly broken » Tokens replacement does not respect hook_tokens documentation
Status: Needs work » Needs review
FileSize
8.81 KB

Here 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/....

fire-wolf’s picture

It works for me. Added patch manually. Before that patch tokens was not listed in 7.x-1.0 version too. Thanks.

sssmmm’s picture

#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 ..

fire-wolf’s picture

Hi!
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!

sssmmm’s picture

infact 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 :)

fire-wolf’s picture

I 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.

sssmmm’s picture

For 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 ..

fire-wolf’s picture

Do you know that conditions and actions availability depends on the event you added?

sssmmm’s picture

Event 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 ..

fire-wolf’s picture

Some people ask for patch for 7.x-1.0 version.

waltercat’s picture

I 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.

NancyDru’s picture

NancyDru’s picture

Status: Needs review » Needs work

I would really, really appreciate someone re-rolling this for the current dev, which has some changes in this area. See #1891374: Tokens issues

Dave Reid’s picture

Status: Needs work » Needs review
FileSize
11.27 KB

Took a stab at this with the current dev. This needs testing before commit.

Dave Reid’s picture

This 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.

NancyDru’s picture

Status: Needs review » Fixed

Thanks so much, Dave. Committed to -dev.

davidwhthomas’s picture

Just 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"

NancyDru’s picture

I'm getting them backwards on a state change rule. However, a "content is viewed" rule produces the correct information.

NancyDru’s picture

I committed a fix for this.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.