Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I've noticed that each entity gets a 'Global Tokens', resulting with a duplication.
Is this for a reason, or can it be moved to it's own section maybe?
Comment | File | Size | Author |
---|---|---|---|
#3 | global_tokens.diff | 3.68 KB | mooffie |
Snap1.png | 14.75 KB | amitaibu |
Comments
Comment #1
fagoIt should be yes, this is currently due to the limitation of the token API. I had no time yet, to create a patch to improve token.
Comment #2
mooffie CreditAttribution: mooffie commentedNote that there's one complexity in fixing this issue:
Tokens such as [node:url] won't be recognized anymore. Do you think that providing an upgrade path (in the .install file) is mandatory to fixing this issue? If you think that we can do without an upgrade path then feel free to assign this issue to me, I think I can handle it.
Comment #3
mooffie CreditAttribution: mooffie commentedHere's my patch.
(It's OK, I solved this. [node:url] and such bogus 'global' tokens are still recognized --but they aren't listed anymore. So this 'backward compatibility' problem is now solved.)
The only problem I found with the token.module is that its theme_token_help() always include global tokens in the listing. So I had to provide a replacement theming function --which is a copy of the original but with a small enhancement.
====
There are two things to consider:
Comment #4
fagofirst off thanks for your efforts on this.
@1: indeed, that will be necessary so that tokens get replaced when only globals are used. We need to fix this before we can patch this.
@2: Indeed, that could be fixed. But I don't think it's likely to produce problems.
@patch: It's
}
else
not
+ } else {
Anyway, I think the better fix would be to get it into the token module, so that it's possible to use theme token help without globals. Perhaps you could give that a try?
Comment #5
mooffie CreditAttribution: mooffie commentedOK. But let me clarify matters:
Tokens do get replaced when only globals are used. That's because
workflow_ng_token_replace()
gets called unconditionally; even ifworkflow_ng_token_get_used_arguments()
returns an empty list.What I did was raise the possibility that in the future things would change; that some further optimization will be carried out. Or that programmers will do
if ($arguments_are_used) { workflow_ng_token_replace() }
.That's why I sugested that
workflow_ng_token_get_used_arguments()
return a dummy '_global' variable: as a guard against these things.However, thinking more about this, I'm not at all sure that this guard is actually needed:
workflow_ng_token_replace()
is efficient enough. (My addition oftoken_replace($text, 'global')
makes it less so, but a simpleif (strtr($text, '[')) { .. }
optimization will solve this.)You be the judge here. Do you want me to return a dummy '_global' from
workflow_ng_token_get_used_arguments()
?It is true that Token's
theme_token_help()
currently lacks this ability, but this is only one detail. The rest of the patch is still needed. That's why I don't see a reason to wait for the Token module. When the Token module gets amended we will simply drop my replacecenttheme_workflow_ng_token_help()
, that's all.(But, parhaps your idea for fixing this issue was completely different than mine?)
Comment #6
JacobSingh CreditAttribution: JacobSingh commentedI'm also keen on getting this resolved...
The patch works great for me.
Comment #7
fagosee http://drupal.org/node/289035 for a try to get it solved in token.