composer update

This commit is contained in:
Oliver Davies 2019-01-24 08:00:03 +00:00
parent f6abc3dce2
commit 71dfaca858
1753 changed files with 45274 additions and 14619 deletions

View file

@ -187,16 +187,7 @@ function webform_lingotek_config_entity_document_upload(array &$source_data, Con
$translation_elements = $translation_manager->getTranslationElements($entity, $entity->language()->getId());
$source_data['elements'] = $translation_elements;
// Encode all [tokens].
$yaml = Yaml::encode($source_data);
$yaml = preg_replace_callback(
'/\[([a-z][^]]+)\]/',
function ($matches) {
return '[***' . base64_encode($matches[1]) . '***]';
},
$yaml
);
$source_data = Yaml::decode($yaml);
_webform_lingotek_decode_tokens($source_data);
break;
case 'webform_options';
@ -212,16 +203,7 @@ function webform_lingotek_config_entity_document_upload(array &$source_data, Con
function webform_lingotek_config_entity_translation_presave(ConfigEntityInterface &$translation, $langcode, &$data) {
switch ($translation->getEntityTypeId()) {
case 'webform';
// Decode all [tokens].
$yaml = Yaml::encode($data);
$yaml = preg_replace_callback(
'/\[\*\*\*([^]]+)\*\*\*\]/',
function ($matches) {
return '[' . base64_decode($matches[1]) . ']';
},
$yaml
);
$data = Yaml::decode($yaml);
_webform_lingotek_decode_tokens($data);
/** @var \Drupal\webform\WebformInterface $translation */
$translation->setElements($data['elements']);
@ -236,3 +218,79 @@ function webform_lingotek_config_entity_translation_presave(ConfigEntityInterfac
break;
}
}
/**
* Implements hook_lingotek_config_object_document_upload()
*/
function webform_lingotek_config_object_document_upload(array &$data, $config_name) {
if ($config_name !== 'webform.settings') {
return;
}
$data['webform.settings']['test.types'] = Yaml::decode($data['webform.settings']['test.types']);
$data['webform.settings']['test.names'] = Yaml::decode($data['webform.settings']['test.names']);
_webform_lingotek_encode_tokens($data);
}
/**
* Implements hook_lingotek_config_object_translation_presave()
*/
function webform_lingotek_config_object_translation_presave(array &$data, $config_name) {
if ($config_name !== 'webform.settings') {
return;
}
_webform_lingotek_decode_tokens($data);
$data['webform.settings']['test.types'] = Yaml::encode($data['webform.settings']['test.types']);
$data['webform.settings']['test.names'] = Yaml::encode($data['webform.settings']['test.names']);
}
/******************************************************************************/
// Lingotek decode/encode token functions.
/******************************************************************************/
/**
* Encode all tokens so that they won't be translated.
*
* @param array $data
* An array of data.
*/
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], array(0x000000, 0x10ffff, 0, 0xffffff), 'UTF-8');
return "[$replacement]";
},
$yaml
);
$data = Yaml::decode($yaml);
}
/**
* Decode all tokens after string have been translated.
*
* @param array $data
* An array of data.
*/
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], array(0x000000, 0x10ffff, 0, 0xffffff), 'UTF-8');
return "[$token]";
},
$yaml
);
$data = Yaml::decode($yaml);
}