Hi!
I am marking this as a support request, but if you find that this is something that needs fixed feel free to change the category.
Here is what I am trying to do. In my Webform the user can select an entity (via entity reference). The referenced entities have a field with an email address. This email address should be the To: email address that the webform submission gets sent to. I am trying to get the email address from the reference entity via a chained token.
On Flocon de toile there is a blog post called: Token and chained entities on Drupal 8. He references the Drupal.org Token issue Chained tokens for field tokens.
Here is the Webform token info for submission values:
[webform_submission:values:?]
Webform tokens from submitted data. Replace the '?' with the 'element_key', 'element_key:format' or 'element_key:format:items'. The 'format' can be 'value', 'raw', or custom format specifically associated with the element The 'items' can be 'comma', 'semicolon', 'and', 'ol', 'ul', or custom delimiter For example, to display the Contact webform's 'Subject' element's value you would use the [webform_submission:value>s:subject] token.
My entity reference field on the webform has a machine name of contact_reason_or_person
My email field on the referenced entities has a machine name of: field_email, so I figure this would be the token:
[webform_submission:values:contact_reason_or_person:entity:field_email]
Web form displays the following in the Webform email To field:
To: [contact_reason_or_person]
I have tried a number of :entity chained tokens and all of them give the same results. I tried the token:
[webform_submission:values:contact_reason_or_person:entity:title]
which I figured all entities should have but it too showed up as:
To: [contact_reason_or_person]
I notice that in another webform issue there is work on tokens being done that may be related Allow Token access to composite sub elements in webform submissions.
Thanks in advance for any assistance you can offer!
Frederick
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | chained_tokens_not-2877360-14.patch | 7.33 KB | jrockowitz |
| #9 | chained_tokens_not-2877360-9.patch | 1.19 KB | jrockowitz |
Comments
Comment #2
jrockowitz commentedFirst #2873307: Allow token access to composite sub elements in webform submissions needs to be committed and then we can think about entity reference chaining.
Comment #3
frederickjhHi jrockowitz!
I first want to say that I am totally blown away by the work you have done on Webform for Drupal 8. I saw you presentation on youtube from Drupalcon Baltimore and a number of your other videos.
I am not sure how to interpret your answer as it relates to my support issue. I understand what you are working on in the related issue. That is why I marked it as related.
My question is, are chained tokens broken or maybe never implemented in Webform?
The Token module seems to have done their part to implement it. I am also concerned that if this is not looked at now the work in #2873307 may break or hinder the ability to allow chained tokens to work.
Since there is no easy way for one to see if they have the correct chained token, as there is no chained token browser, I am just trying to confirm that this is broken or never worked in Webform and not that I just do not have the correct chained token.
Thanks again for any help you can give!
Frederick
Comment #4
acbramley commentedI've been looking at implementing something like this today as well. Now that #2873307: Allow token access to composite sub elements in webform submissions is in we can start looking at this as well.
Comment #5
hanoiiI second the blown away on the work done :).
And truly would love to be able to chain somehow, I am using a term reference field where I also want to get an email out of the entity.
Comment #6
jrockowitz commentedWhile refactoring token handling via #2884624: Allow composite sub elements to be formatted I found a relatively easy way to implement this.
The syntax, once that patch is committed will be
[webform_submission:values:contact_reason_or_person:entity:field_email]Comment #7
jrockowitz commentedThis issue has been fixed. Please download the latest dev release to review.
Comment #8
thestevelavigne commentedI am trying to do the same thing.
[webform_submission:values:location:entity:field_email]
Where location is a entity reference to a taxonomy and field_email the email address I want to place in the to.
No matter what I put, the output is the entire rendered display including all fields.
I have tried:
[webform_submission:values:location:entity]
[webform_submission:values:location:entity:field_email]
And both give me the exact same result.
Comment #9
jrockowitz commentedComment #11
jrockowitz commentedI committed the patch and taxonomy terms and vocabularies should now support token chaining.
Comment #12
thestevelavigne commentedThanks!
Does it change how the token is formed? I implemented the patch and I am still getting issues only with taxonomy term entity references.
Comment #13
thestevelavigne commentedComment #14
jrockowitz commentedThe moral of the story is to assume nothing "just works" and write some tests.
The attached patch includes a test for the '[webform_submission:values:term:entity:name]' token.
Comment #16
jrockowitz commentedI committed the patch.
Comment #18
biigniick commentedis it possible for this to work in D7?
Comment #19
jrockowitz commented@BiigNiick The Webform module for Drupal 8 is a completely new codebase. I recommend searching the Webform D7 issue queue for an existing ticket and if you can't find one, then create a 'Feature request' in the D7 issue queue.
Comment #20
biigniick commented@jrockowitz thanks!
Comment #21
handkerchiefWhat about token chaining of other entities? If we reference to a node or eck for example. Is there no way to get the field values of the referenced entities?
[webform_submission:values:reference_field_to_eck:entity:field_of_eck]
[webform_submission:values:reference_field_to_node:entity:field_of_node]
Comment #22
handkerchiefNevermind, it works fine, I had a typo.