Problem/Motivation
It could be useful to allow the use of nested tokens. Take a look at the user scenario at #2076821: Please allow for nested tokens.
Here is what should theoretically work:
[aet:node:[view:url:args:value:1]:title]The inner token is returning the correct value but the outer one is not, so the output currently is:
[aet:node:42:title]
Without knowing, well, anything about the performance issue, I suggest a recursive call to token_replace(). That function already returns the text as it is if it couldn't find any tokens. By calling the function again, this would allow us to replace token after token after token until there are no tokens left.
I haven't done any research regarding this for Drupal 8. This is just a proposal to get the conversation going.
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | token-nested_tokens-2082269-2.patch | 729 bytes | olofbokedal |
| #1 | token-nested_tokens-2082269-1.patch | 547 bytes | olofbokedal |
Comments
Comment #1
olofbokedal commentedHere's a patch that implements this.
Comment #2
olofbokedal commented#1 resulted in an infinite loop if there were no replacements available. Fixed by a simple if-statement that returns the text if there are no replacements available.
Comment #3
nithinkolekar commentedsorry, wrong issue..
Comment #4
shaneonabike commentedThis is fairly important and useful with relation to modules that replace a token's ? with an actual node id or other value from another variable.
Comment #5
robertwb commentedI can report that the patch in #2 works as advertised and is a really useful feature. Is there any possibility of recursion if, for example, one referenced a text containing token that contained a token reference to itself?
Comment #8
gaddman commentedThis is still an issue in 10.5. And must be something a few people want, since the ECA module supports this: https://ecaguide.org/plugins/eca/base/actions/eca_token_replace/
Comment #9
quietone commentedHi, in Drupal core changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to the Core change policies. Thanks.
Is this a problem on Drupal 11.x?