In rules_tokens(), the call to entity_token_tokens() should be replaced with module_invoke('entity_token', 'tokens', ...).
Since it is implemented in a separate include file, that include file might not be loaded yet if no calls to module_implements('tokens') has been done yet.
So calling the function directly can result in a fatal error - undefined function.
This is not an issue if rules_tokens() itself is called by the usual module_invoke_all() or looping on module_implements() results, etc, so it has not been notices as an error by most users. But if some module calls module_invoke('rules', 'tokens') specifically, then the error might happen.
Comments
Comment #2
dagmarHere is this patch.
Comment #3
mykola dolynskyiJust faced such problem with Rules 7.x-2.9
Fatal error: Call to undefined function entity_token_tokens() in /var/www/mydom/sites/all/modules/rules/rules.module on line 1671Comment #4
mykola dolynskyiin my case patch resulted that any tokens (not related to entities, just primitive strings too) was not solving in rules.
This patch works better
Comment #5
tr commentedI can see that is some very edge cases perhaps entity_token.tokens.inc is not loaded at the point when rules_tokens() is invoked. But there are easy workarounds for this if you are encountering that situation, and as the original poster points out this will not happen to most people.
The problem with the patch is that replacing the call to
entity_token_tokens()withmodule_invoke('entity_token', 'tokens', ...)does not actually force entity_token.tokens.inc to be loaded, so it does not solve the problem. The only thing it does is to hide the error message. Essentially,module_invoke()is just calling function_exists() to check if entity_token_tokens() exists before using it. If it doesn't exist, then it's never loaded. So this patch does not fix the problem, just hides it.I'm marking this as "won't fix" because it really doesn't affect a lot of users, and those users have an easy work-around of using
module_load_include()in their own code if they want to callmodule_invoke('rules', 'tokens')directly. IMO the potential problems caused by changing how include files are loaded at this point in the D7 lifecycle far outweigh the benefits.Comment #6
anybodyFYI: Just ran into the same issue when submitting an entity form:
Error: Call to undefined function entity_token_tokens() in rules_tokens() (Zeile 1711 von /sites/all/modules/contrib/rules/rules.module).
Using Rules 7.x-2.12
EDIT: Updating to Rules 7.x-2.13 fixed the issue!