I've written a Drupal 8 webform handler plugin that sends webform submission data to another server via REST. I'm trying to send all the populated fields of the form to the third-party server so that it can be viewed in the "message" field of their UI. I've tried using the [webform_submission:values] token with the 'html' suffix, but it comes out as a unrendered block of html code. Is there a token suffix that will format the webform values as plain text with new line characters after each value?

Here's an example of the JSON I'm sending to the 3rd party server:

   "u_user": "[webform_submission:values:user:raw]",
   "u_service": "Foo Service",
   "assignment_group": "Bar Assignment Group",
   "u_service_provider": "Baz",
   "short_description": "[webform_submission:values:subject:raw]",
   "comments": "[webform_submission:values:html]"

I need to implement this across nine different forms, some of which have conditional logic, so hard-coding every field into every handler is impractical.

Also is there a resource on the web that lists all the suffixes and prefixes for tokens?

  • Sounds like you should create a custom token if the token you ask for does not exist yet. You could simply start by copying the code for the [webform_submission:values] token and then adjust it to your needs. – leymannx Nov 9 '20 at 14:19

Thanks @leymanx for the suggestion to make my own custom token. That's what I did. I created a hook_tokens function that borrowed code from webform.tokens.inc hook_tokens implementation. I deleted anything that didn't relate to the one token I was after, then created a _module_name_token_get_submission_values function that also borrowed heavily from the corresponding function in the webform module. Finally, I wrote a function that performed a series of preg_replace substitutions on the html code that was giving the destination server problems.

Along the way, I learned a lot about custom tokens and was able to refactor my plugin to eliminate the need for a completely separate plugin through the use of a custom token. :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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