protected function WebformTranslationLingotekManager::encodeTokens in Webform 6.x
Encode all tokens so that they won't be translated.
Parameters
array $data: An array of data.
3 calls to WebformTranslationLingotekManager::encodeTokens()
- WebformTranslationLingotekManager::configEntityDocumentUpload in src/
WebformTranslationLingotekManager.php - Implements hook_lingotek_config_entity_document_upload().
- WebformTranslationLingotekManager::configEntityTranslationPresave in src/
WebformTranslationLingotekManager.php - Implements hook_lingotek_config_entity_translation_presave().
- WebformTranslationLingotekManager::configObjectDocumentUpload in src/
WebformTranslationLingotekManager.php - Implements hook_lingotek_config_object_document_upload().
File
- src/
WebformTranslationLingotekManager.php, line 192
Class
- WebformTranslationLingotekManager
- Defines a class to translate webform Lingotek integration.
Namespace
Drupal\webformCode
protected function encodeTokens(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);
}