You are here

protected function WebformTranslationLingotekManager::decodeTokens in Webform 6.x

Decode all tokens after string have been translated.

Parameters

array $data: An array of data.

2 calls to WebformTranslationLingotekManager::decodeTokens()
WebformTranslationLingotekManager::configEntityTranslationPresave in src/WebformTranslationLingotekManager.php
Implements hook_lingotek_config_entity_translation_presave().
WebformTranslationLingotekManager::configObjectTranslationPresave in src/WebformTranslationLingotekManager.php
Implements hook_lingotek_config_object_translation_presave().

File

src/WebformTranslationLingotekManager.php, line 213

Class

WebformTranslationLingotekManager
Defines a class to translate webform Lingotek integration.

Namespace

Drupal\webform

Code

protected function decodeTokens(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);
}