I'm currently working on the rules module, an improved port of workflow-ng.

It features the concept of input evaluators. They make it possible to extend *every* action with *every* added input evaluator. Rules itself provides a php input evaluator and another obvious one is one for token.

I'd like to add it to the token module, for this reason:
* When the token module is improved, it's easy to make use of the improvements. E.g. the 'global' token situation is not ideal for the module and when I've time I'd like to work on token to improve it. Then the token rules module integration can rely on it without version conflicts.

* Of course this would also help with bigger API changes like this and the one we already talked about several times. However, rules won't be the only affected module, so this isn't really a point.

The code comes as a separate include file which is included automatically by the rules module. So people not having the rules module are not influenced in any way.

Note: To test this, you need the latest rules development snapshot. Best it's tested with the "Show a message" system action.

Comments

fago’s picture

ah perhaps I'll add some notes to the token cache clearing code it implements. It's basically ported from workflow-ng. It's necessary as rules and workflow-ng works with variables in different states, e.g. the unchanged node and the changed node on node update. To reflect this changes when token works on both nodes I need to clear the cache.
This is also the cause why I don't use token_replace_multiple() - I might have multiple variables of the same type.

fago’s picture

ok some more on this and how rules/workflow-ng uses token:

* rules/workflow-ng allows to make use of tokens nearly everywhere - which leads to things which are quite useful, but were not intended originally for the integration. I'm referring to things like using a token together with the string comparison condition to check whether a node is published. I understand that this is no usual token use case and I don't suggest to develop token in such a direction.

But also token is used as it should be, for replacements in on site messages, mails, log messages, breadcrumbs, ...

* Token improvements I suggested were always for "valid" use cases like pre-selection and filtering of raw tokens vs safe tokens and the performance thingie.

* For other use cases rules already has a "php input evaluator" and I'll add conditions for such simple things as checking whether a node is published.

Anyway the patch isn't about any token improvements. It just empowers rules to make use of token replacements and could also go into the rules module. As rules allows other module to provide input evaluators it would make sense to put it into token though.

If you prefer to not have it in the token module, it's no problem. I 'd go and add it to the rules module then. I just suggested to add it to token, because I would say
* it's the cleaner way (rules provides the hook, token implements it)
* it's easier to deal with token API changes/improvements.

fago’s picture

StatusFileSize
new2.59 KB

if someone wants to use it in the meanwhile:

Just download the attached file, rename it to token.rules_.inc and place it in your token module directory. Then go to the administer modules page and just hit submit - that's it.

greggles’s picture

Status: Needs review » Reviewed & tested by the community

Given that this has no impact on the token module itself and given your solid points about how this could be beneficial in the long run, I'm inclined to commit it.

Marking RTBC to reflect that.

@eaton - can you review and state an opinion?

fago’s picture

yep, that would be great. I'm working towards the first beta release - I'd like to have this issue sorted out until the beta, so people don't have troubles getting token integration :)

ethanw’s picture

Thanks for this patch fago, and thank you for making it so easy to apply!

One note: I think the file should be renamed token.rules.inc, not token.rules_.inc

For those who are interested, the include is done by _rules_include_get_files in rules.module.

fago’s picture

yes, it should be token.rules.inc. Thanks for clarifying this.

eaton’s picture

I'm not really comfortable adding a lot of other module-specific logic and behavior to token. Is there any reason that this support can't simply be included with rules module?

Token is listed as a dependency for so many other projects at this point that I'm not sure why the code would go here rather than in rules. Even the CCK specific field handling code was migrated from token to CCK module...

I'm willing to be convinced, but I'm just not sure it makes sense to put it here. Wouldn't it be more beneficial to have it in rules.module so that it can be updated and evolve along with that code?

fago’s picture

>Is there any reason that this support can't simply be included with rules module?
No, it can be with rules.

>Are there reasons to put it into token?
Imho
* it's the cleaner way (rules provides the hook, token implements it)
* it's easier to deal with token API changes/improvements.

>Wouldn't it be more beneficial to have it in rules.module so that it can be updated and evolve along with that code?
I think it could better evolve in token - as it could evolve with improvements of token. I plan to not change the rules (input evaluator) API after the beta.

So the dependency thing isn't the problem. There is no real problem having it in rules - it'd be just like the CCK integration which was in token: It works, but it would better fit the other way.

greggles’s picture

* it's easier to deal with token API changes/improvements.

This is the reason I'm motivated to commit it.

The Date module went through API changes from 5.x-1.x to 5.x-2.x so we had to move the Date token code to Date module which was somewhat painful. For a while Date+Token were causing WSOD on a fair number of sites. If we can prevent that, I think we should.

greggles’s picture

Title: add rules integration » add rules integration to token module
Status: Reviewed & tested by the community » Fixed

After some more discussion we decided to include this.

@fago, thanks a lot for providing the code and the discussion on why it should be committed.

fago’s picture

ah, great! thanks a lot!

I've just released the beta yesterday, so it's awesome to have it committed now :)

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

emilyf’s picture

Wasn't sure if I should start a new issue or not, but after following this thread I downloaded the dev version of token to be used with rules. am using tokens in triggered action to send an email when content is changed. Most of the tokens are working but [node:title] and [node:title-raw] are not coming through. It ends up empty where that token was....

Stalski’s picture

Status: Fixed » Active

I have taken this to a new issue in rules. Because it has nothing to do with friendlist imo. Those are the actions working fine (user and node token replacements). I just found it related to this article.
Thx

fago’s picture

Category: task » bug
Status: Closed (fixed) » Fixed

Please don't reopen fixed issues like this, open a new one. If the problems appear only in friendlist actions, open an issue there. Else open a rules issue.

Status: Active » Closed (fixed)

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