You are here

function _webform_lingotek_decode_tokens in Webform 8.5

Decode all tokens after string have been translated.

Parameters

array $data: An array of data.

2 calls to _webform_lingotek_decode_tokens()
webform_lingotek_config_entity_translation_presave in includes/webform.translation.inc
Implements hook_lingotek_config_entity_translation_presave().
webform_lingotek_config_object_translation_presave in includes/webform.translation.inc
Implements hook_lingotek_config_object_translation_presave().

File

includes/webform.translation.inc, line 425
Webform module translation hooks.

Code

function _webform_lingotek_decode_tokens(array &$data) {
  $yaml = Yaml::encode($data);
  $yaml = preg_replace_callback('/\\[([^]]+?)\\]/', function ($matches) {

    // Decode token HTML entities to characters.
    // @see https://stackoverflow.com/questions/6720826/php-convert-all-characters-to-html-entities.
    $token = mb_decode_numericentity($matches[1], [
      0x0,
      0x10ffff,
      0,
      0xffffff,
    ], 'UTF-8');
    return "[{$token}]";
  }, $yaml);
  $data = Yaml::decode($yaml);
}