You are here

function _webform_lingotek_encode_tokens in Webform 8.5

Encode all tokens so that they won't be translated.

Parameters

array $data: An array of data.

3 calls to _webform_lingotek_encode_tokens()
webform_lingotek_config_entity_document_upload in includes/webform.translation.inc
Implements hook_lingotek_config_entity_document_upload().
webform_lingotek_config_entity_translation_presave in includes/webform.translation.inc
Implements hook_lingotek_config_entity_translation_presave().
webform_lingotek_config_object_document_upload in includes/webform.translation.inc
Implements hook_lingotek_config_object_document_upload().

File

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

Code

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

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