I’m on Drupal 9. I need to load the options labels of a Webform’s option programmatically.
So far, I’ve managed to load the labels:
$element = $webform_submission->getWebform() ->getElement($element_key, TRUE); $option_text = WebformOptionsHelper::getOptionText($element_value, $element['#options']);
However, I also need to get those labels for both the language of the site – en
and it
.
The webform object hasn’t a getTranslation()
method, so I’ve tried:
-
relying on
$webform_submission->getTranslation($langcode)
, but that doesn’t work, as it exists only for the language the webform was submitted -
trying to use:
$test = Drupal::service('entity.repository') ->getTranslationFromContext($webform, $langcode); // get the options values
but that doesn’t work either, the labels are always in it
if the webform has been submitted in it
and similarly for en
.
How can get the options for both languages?