1

I'm using Webform 8.x-5.8.

I've got a select box referencing some content. Of course, the numeric option value is passed. But when I reference submitted data with tokens, I just want to handle the plain text appearing with the options, but a concatenation of the text and the sequence " (NID)" is displayed instead, where NID is the content ID. An example with dummy code, names and values - just to roughly show what I suppose is happening behind - is following.

<select name="my_parameter">
<option value="80" selected>Some text</option>
...
...
...
</select>

By selecting Some text, "80" is passed.

My aim is displaying "Some text" picking it up from the submitted values.

Tried with [webform_submission:values:my_parameter] and [webform_submission:values:my_parameter:value]. Anyway I get Some text (80).

What am I supposed to do in order to get rid of that final NID in brackets?

Thanks in advance!

Andrea

  • What is Some text? Is it the node title? – leymannx Sep 24 at 9:02
  • @leymannx Yes, it is. – AppLEaDaY Sep 24 at 9:26
  • It's not clear to me where exactly you are using these tokens, but when in custom code you could do \Drupal::entityTypeManager()->getStorage('node')->load($nid)->label() to get the node title, where $nid is the node ID. – leymannx Sep 24 at 9:40
  • @leymannx I'm using tokens to configure Webform. Supposing the text is the name of a course and the NID is the id of the related content. I have to configure Webform in order to send a message telling something like "You applied for This Course". So far I got something like "You applied for This Course (80)", where "80" is the nid of the content (a course edition with dates). I didn't ask for that concatenation. – AppLEaDaY Sep 24 at 9:56
  • 1
    @leymannx, many thanks! [webform_submission:values:ELEMENT_KEY:entity:title] did the trick! :-) For the sake of completeness, I didn't try [webform_submission:values:ELEMENT_KEY:0:entity:title] - I felt like I can stop since the previous did work. As for the previous suggestions: [webform_submission:values:ELEMENT_KEY:clear] did not work, and I didn't try with "raw" since I remembered I already did in vain previously. I wonder anyway why such a concatenation turned out to be a default and, besides, why I could not find any track for the remedy. – AppLEaDaY Sep 27 at 17:54
0

I scanned Webform's code base for [webform_submission:values: and eventually found the webform.token.inc file to list a number of Webform tokens from submission values. One of them being entity:*. And another being delta.

'<li>element_key:entity:*</li>' .
'<li>element_key:delta:entity:*</li>'

The 'entity:*' applies to the referenced entity
The 'delta' is the numeric index for specific value

And when I scan Drupal core's code base for :entity:title] there's [comment:entity:title]. When I scan for just :title] there's [node:title] among the first hits. Okay, with all that I'd assume it must work with either:

[webform_submission:values:ELEMENT_KEY:entity:title]

Or if it's a multi-value field try it with a :delta of 0 to ensure you only get the first referenced node's title.

[webform_submission:values:ELEMENT_KEY:0:entity:title]
| improve this answer | |

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.