I want to use Webform 8.x-5.x in Drupal 8 to create a personal contact form to be used by logged in users to send personal messages to each other.

At the same time I am using the Profile module to store other information for these users, including a Display Name for them.

Now, on the personal contact form I'd like to show the Display Name of the logged-in user in a "From" text field, and the Display Name of the recipient user in a "To" text field.

I know how to display a token as a default value in a text field. However the Token UI shows the global and Webform tokens only.

I also know that I can make my own module and use hook_token_info() and hook_tokens() to get the Display Name into a token.

But once I have my tokens with the desired information, how do I then get them to show up in the Webform Token UI so that I can use them as default values for my text fields on the form?

To be more precise, the question is, how do I get non-global and non-Webform tokens to show up in the Webform Token UI so that I can use them in Webform?

  • [current-user:display-name] works in webforms and should show up in the token info if you have the Token module installed. Also custom tokens will show up, if they don't depend on data which is not available. This is the case if the token is not for the current user, but for an arbitrary user, which the token doesn't know.
    – 4uk4
    Commented Jul 7, 2017 at 6:55
  • The token UI should be including 'webform_submission' tokens. Where in the Webform module's UI is the 'webform_submission' and 'current-user' token missing?
    – jrockowitz
    Commented Jul 7, 2017 at 10:56
  • @jrockowitz The 'webform_submission' and 'current_user' tokens are not missing. I wanted my own, custom tokens to show up in the UI. But meanwhile I have solved it. I have implemented hook_token_info() and hook_tokens(). As @4k4 mentioned, my custom tokens just show up and I can use them.
    – geroldk
    Commented Jul 7, 2017 at 11:24

1 Answer 1


To add a custom token namespace to the Webform UI, you are going to have to implement HOOK_preprocess_token_tree_link() and add your custom token namespace to the 'token_types'.

@see template_preprocess_token_tree_link() in the token.module.

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.