3

I'm trying to setup a webform that sends links which can be accessed to download a file. It's working with the first file already, but I can't figure out how to create the token for the other files referenced in a multivalue field:

What's working (for one file):

Here is your requested download: <a href="[webform_submission:node:field_gated_download:entity:field_media_file:entity:url]" target="blank">[webform_submission:node:field_gated_download:entity] </a>

I have tried:

[webform_submission:node:field_gated_download:entity:field_media_file:entity:url:0]
[webform_submission:node:field_gated_download:entity:field_media_file:entity:url:und:0]
[webform_submission:node:field_gated_download:0:entity:field_media_file:entity:url]
[webform_submission:node:field_gated_download:und:0:entity:field_media_file:entity:url]

in almost every combination. It's not working.

Can someone lead me in the right direction?

7
  • Before diving deeper into this question I have another question: how do you know how many files are uploaded when defining these tokens? Is there always a set amount of files to be downloaded? Nov 2, 2020 at 14:50
  • 1
    Right now the field is set to unlimited but it could easily reduced to a set amount if that helps.
    – Volker
    Nov 2, 2020 at 15:25
  • Unfortunately not because you still don't now how many files are actually uploaded when adding the tokens. So if you manage to get it working with url:0, 1, 2, etc. and only 1 file is uploaded, you would have multiple dead links in the submission mail. Nov 3, 2020 at 7:51
  • 3
    Right now the field is set to unlimited @rémy better to have flexibility. A good solution for this case is to create a custom token that will print all the links.
    – No Sssweat
    Nov 11, 2020 at 12:09
  • 1
    What about using hook_tokens to interpret the tokens yourself?
    – Beau
    Nov 14, 2020 at 0:45

1 Answer 1

2
+50

One approach to this issue is to interpret tokens on your own via hook_tokens().

hook_tokens() is called every time a token is interpreted and gives you an opportunity to determine how that token is interpreted. Even though the token [webform_submission:node:field_gated_download:entity:field_media_file:entity:url] is already defined, it may be necessary to also implement hook_token_info() or hook_token_info_alter() in order to define additional modifiers to the token.

It's possible that you might discover the exact token syntax that you need by inspecting the arguments passed into hook_token_info_alter().

Here are two tutorials that cover using both hook_token_info() and hook_tokens() in order to perform custom token processing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.