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

Comments

olofbokedal’s picture

StatusFileSize
new547 bytes

Here's a patch that implements this.

olofbokedal’s picture

StatusFileSize
new729 bytes

#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.

nithinkolekar’s picture

Issue summary: View changes

sorry, wrong issue..

shaneonabike’s picture

This 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.

robertwb’s picture

I 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?

Version: 7.23 » 7.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.

Status: Active » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.

gaddman’s picture

Version: 7.x-dev » 10.5.x-dev
Status: Closed (outdated) » Needs work

This 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/

quietone’s picture

Version: 10.5.x-dev » 11.x-dev
Issue summary: View changes

Hi, 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?

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.