protected function LingotekContentTranslationService::setCohesionComponentValues in Lingotek Translation 3.6.x
Same name and namespace in other branches
- 4.0.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::setCohesionComponentValues()
- 3.5.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::setCohesionComponentValues()
- 3.7.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::setCohesionComponentValues()
- 3.8.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::setCohesionComponentValues()
1 call to LingotekContentTranslationService::setCohesionComponentValues()
- LingotekContentTranslationService::saveTargetData in src/
LingotekContentTranslationService.php - Save the entity translation.
File
- src/
LingotekContentTranslationService.php, line 918
Class
- LingotekContentTranslationService
- Service for managing Lingotek content translations.
Namespace
Drupal\lingotekCode
protected function setCohesionComponentValues(array $component_model, $model, $translations, $path = []) {
foreach ($translations as $key => $translation) {
// If the key does not match a UUID, then it's not a component field and we can skip it.
if (!preg_match(ElementModel::MATCH_UUID, $key)) {
continue;
}
$component = $component_model[$key] ?? NULL;
// If we can't find a component with this uuid, we skip it.
if (!$component) {
continue;
}
// Keep track of the path to the property so we can handle nested components.
$property_path = array_merge($path, [
$key,
]);
$settings = $component
->getProperty('settings');
$component_type = $settings->type ?? NULL;
$schema_type = $settings->schema->type ?? NULL;
switch ($schema_type) {
case 'string':
$model
->setProperty($property_path, $translation);
break;
case 'array':
foreach ($translation as $index => $item) {
$newPath = array_merge($property_path, [
$index,
]);
$this
->setCohesionComponentValues($component_model, $model, $item, $newPath);
}
break;
case 'object':
switch ($component_type) {
case 'cohWysiwyg':
$newPath = array_merge($property_path, [
'text',
]);
$model
->setProperty($newPath, $translation);
break;
default:
\Drupal::logger('lingotek')
->warning('Unhandled component type of \'%type\' (schema type: %schema) encountered when setting cohesion component values.', [
'%type' => $component_type,
'%schema' => $schema_type,
]);
break;
}
break;
default:
\Drupal::logger('lingotek')
->warning('Unhandled schema type of \'%type\' encountered when setting cohesion component values.', [
'%type' => $schema_type,
]);
break;
}
}
}