I have written a custom handler in Drupal 8 D8 that grabs submitted data from a webform and reformats it and sends it to a JSON webservice. That is all working perfectly. My issue is that the submitted data from 2 of the dropdowns is an integer (the key of the dropdown), rather than the value of the drop down, like it was when in D7 I called:

$components = $node->webform['components'];

which gave me the value of the data from the dropdowns. Now I am calling:

$values = $webform_submission->getData();

Which gives me the submission data. However, what I need to do is translate the number to the value. For example:

for a component (or element) drop down called 'numbers' the options are: 1|One 2|Two 3|Three

When I grab the submission data I get "1" but I want to send the word "One".

How do I load the dropdown element to translate the value '1' to the word "One" in Drupal 8?


1 Answer 1


When I grab the submission data I get "1"

This is standard in Drupal for select & radio fields, you always get the key.

So all we have to do is use the key to retrieve the value.

$key = $webform_submission->getData()['field_select'];

// retrieve webform fields.
$webform_fields = $webform_submission->getWebform()->getElementsDecoded();

// use key to retrieve value of field_select.
$value = $webform_fields['field_select']['#options'][$key];

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.