public function AcquiaCohesionDataConverter::findAndConvertCohesionJsonDataToCohesionXmlData in TMGMT Translator Smartling 8.4
Converts Cohesion's JSON components to TMGMT Smartling's XML data items.
Parameters
array $data:
Return value
array
File
- modules/
tmgmt_smartling_acquia_cohesion/ src/ AcquiaCohesionDataConverter.php, line 46
Class
- AcquiaCohesionDataConverter
- Class AcquiaCohesionDataConverter @package Drupal\tmgmt_smartling_acquia_cohesion
Namespace
Drupal\tmgmt_smartling_acquia_cohesionCode
public function findAndConvertCohesionJsonDataToCohesionXmlData(array $data) {
$newData = [];
foreach ($data as $jobItemId => $jobItemData) {
foreach ($jobItemData as $jobItemDataEncodedFieldKey => $jobItemDataFieldValue) {
if ($layoutCanvas = $this
->isLayoutCanvas($jobItemDataFieldValue["#text"])) {
$xmlDataItems = [];
$jobItemDataDecodedFieldKey = $this->xmlPlugin
->decodeIdSafeBase64($jobItemDataEncodedFieldKey);
foreach ($layoutCanvas
->iterateModels() as $model) {
$modelUuid = $model
->getUUID();
foreach ($model
->getValues() as $modelPropertyUid => $modelPropertyValue) {
// Skip component title.
if ($modelPropertyUid == 'settings') {
continue;
}
$suffix = self::TMGMT_SMARTLING_ACQUIA_COHESION_KEY_DELIMITER . 'model:' . $modelUuid . ':property:' . $modelPropertyUid;
$encodedKey = $this->xmlPlugin
->encodeIdSafeBase64($jobItemDataDecodedFieldKey . $suffix);
$slVariant = $jobItemDataFieldValue['sl-variant'] . $suffix;
if (!$this
->isTranslatableProperty($modelPropertyValue)) {
continue;
}
// HTML text.
if ($this
->isCohesionPropertyHtmlText($modelPropertyValue)) {
$this->logger
->info('Exporting Acquia Cohesion rich text field: model=@modelUid property=@propertyUid', [
'@modelUid' => $modelUuid,
'@propertyUid' => $modelPropertyUid,
]);
$xmlDataItems[$encodedKey] = [
'#text' => $modelPropertyValue->text,
'#format' => $modelPropertyValue->textFormat,
'sl-variant' => $slVariant,
];
}
else {
$this->logger
->info('Exporting Acquia Cohesion plain text field: model=@modelUid property=@propertyUid', [
'@modelUid' => $modelUuid,
'@propertyUid' => $modelPropertyUid,
]);
// Plain text.
$xmlDataItems[$encodedKey] = [
'#text' => $modelPropertyValue,
'sl-variant' => $slVariant,
];
}
}
}
$newData[$jobItemId] += $xmlDataItems;
}
else {
$newData[$jobItemId][$jobItemDataEncodedFieldKey] = $jobItemDataFieldValue;
}
}
}
return $newData;
}