Support from Acquia helps fund testing for Drupal Acquia logo

Comments

klausi’s picture

Title: Have site tokens in send mail actions » Have site tokens in actions
Category: feature » bug

I remember that was possible as the site-wide tokens were always added to the tokens of any variable. Now they are gone, so this is a valid bug report. Something must have changed in token.module

bsztreha’s picture

subscribe

fago’s picture

Title: Have site tokens in actions » Global tokens are unavailable
fago’s picture

Priority: Normal » Major

Ouch, the token module changed....

malks’s picture

Does this mean that this won't get fixed until the token module is fixed?

fago’s picture

No, we'll have to roll a patch for the token module - as its rules integration lives there.

malks’s picture

Is there an issue in the token queue for this then? I'm going to just write my own action I think to get around my particular use case, but happy to try and get a patch going against token if that helps.

malks’s picture

I'm trying to work through this and rules being such a complex module I'm having to muddle at the best. What I'm finding though is that isn't it best to have responsibility for the global tokens in Rules? That is, shouldn't rules always load in global tokens as a variable/argument? Does this sound on the right direction or am I missing something.

Malks.

ionmedia’s picture

i have global section in tokens for another modules
CCK cck_phone
CCK content_taxonomy
CCK date
CCK file
CCK gmaps address
CCK gmaps point
CCK link
CCK node reference
CCK number
CCK serial
CCK text
CCK vinfield
Global
Node

thats from /admin/build/path/patterns

maybe for a rule it was able to build such list:
user1
--....
user2
--....
Global
--site-name
--date
--...
Node
--....
--CCK number
----....
--CCK serial
--CCK text
--.....

now i use rules 6.x-1.3 and there is no global tokens, how can i use site-name ?

apmsooner’s picture

I have both the latest versions of rules and token and had an original token used in a rule of [node:site-name] and it still works so it seems the tokens still function but just not visible in the rules interface right?

malks’s picture

I think if you have a rule (or rule set) that has arguments, in apmsooner's case a node, then the global tokens get loaded against that so [node:site-name] will work (I suspect that [global:site-name] won't work), but if there are no arguments (as in the case of scheduled rule sets) then you will not be able to get to them.

drupaljaipur’s picture

FileSize
2.64 KB

used token-6.x-1.15 module

changes done in token.rules.inc file to make global tokens available in rules action.

Govind

fago’s picture

Title: Global tokens are unavailable » global tokens are missing in Rules
Project: Rules » Token
Component: Rules Engine » Code
Status: Active » Needs work
Issue tags: +rules integration

Patches again the token module should be posted into the token issue queue.

The patch contains some random line changes and introduces some trailing white-spaces, as well as commented out code. Take care of that. Be sure to follow the drupal coding standards.

 $used_vars[] = 'global';

We need to use a var-name that may not occur else (e.g. :global) + we need to really identify whether a global token has been used at all and only then run the global token replacements.

drupaljaipur’s picture

Issue tags: -rules integration
FileSize
1.74 KB

Thanks for the advise fago. I tried to follow it.

I couldn't understand what you mean by "use a var-name that may not occur else (e.g. :global)" but tried to identify whether global token is being used and then only run the global token replacement.

fago’s picture

So there is

+  if ($used_vars || strpos($text, TOKEN_PREFIX. 'global' .':') !== FALSE) {

and below

     foreach ($used_vars as $name) {
+    
+      if ($name != 'global'){ 

So is global now in the used vars or not? Anyway, the approach token of the token integration *scans* for token usage in preparation, so the above strpos() shouldn't be necessary at run-time. That said, global should be in the used-vars. However, there might be rules variable of name 'global' what would lead to conflicts. Thus, use ':global' inside $used_vars to avoid conflicts (+ document that with a comment).

+      if ($name != 'global'){ 
       $type = _token_rules_map_type($state['variables'][$name]->info['type']);
+      }
+      else {
+      $type = 'global';
+      $vars['global'] = 'global';
+      }

Watch out for the coding standards! (indention, spacing)

Also, we could make use of the new token treewidget for the token help, but that's another issue.

barraponto’s picture

Issue tags: +tokens

please fago, would you be so kind as to provide a patch for this?

nadavoid’s picture

subscribing

Danny Englander’s picture

I realize now I was experiencing this same issue here: http://drupal.org/node/1045516

chrislabeard’s picture

Nothing since Feb? How people living without global tokens?

Dave Reid’s picture

@chrislabeard: Feel free to learn the patching process and make the modifications suggested in #15 to the patch in #14.

pbeakley’s picture

subscribing

auth’s picture

Status: Needs work » Needs review
FileSize
1.06 KB

Attached patch based on #14 with feedback from #15.

nadavoid’s picture

Spot checked #22, using [:global:site-date-month] and [:global:site-name], which will be great for sending emails.

Attaching an updated patch, only adding a comment, about the leading ":" in ":global"

auth’s picture

Experienced issue with tokens not being replaced in text comparision. Refactored patch and included comment in #23 to handle this.

auth’s picture

Attached wrong file in #24, attaching correct file.

Experienced issue with tokens not being replaced in text comparision. Refactored patch and included comment in #23 to handle this.

timd.mackey’s picture

Global tokens seem to be working, thanks for the patch.

timd.mackey’s picture

Hmm, while global tokens are working now, it appears that this has caused problems with the user: and account: tokens. I'm using the account: token within a Rule that sends an email to a particular user, however the account: token (which should be the specific registered user) is instead being translated as the user: token (the acting user/administrator). I.E. - If I have a Rule which sends a user a one-time-login link to their account, instead they receive an email with a one-time-login for the administrator's account--big problem. I'm pretty sure this is caused somehow by the patch, because after I rolled back the patch, the account: token took the correct value again.

auth’s picture

Could you please test your use case against this updated patch?

timd.mackey’s picture

Woo-hoo, #28 works! Thanks for the new patch.

dkingofpa’s picture

#28 is working for me as well. Thanks auth.

havran’s picture

#28 Working for me. Thanks.

Danny Englander’s picture

#28 works!!

timd.mackey’s picture

Status: Needs review » Reviewed & tested by the community

I'd say this qualifies as #28 being Reviewed and Tested.

Dave Reid’s picture

Status: Reviewed & tested by the community » Fixed

Committed #28 to 6.x-1.x. Thanks everyone for patching and testing!
http://drupalcode.org/project/token.git/commit/43e1993

Status: Fixed » Closed (fixed)
Issue tags: -tokens

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