Refactor to account for migration of translated entities
This commit is contained in:
parent
4ee8a3b418
commit
050676f4bd
1 changed files with 34 additions and 20 deletions
|
@ -50,15 +50,30 @@ class MigrationHelperFieldTransformations {
|
|||
|
||||
foreach ($entities as $entity) {
|
||||
$media_target_ids = [];
|
||||
$langcodes = $entity->getTranslationLanguages();
|
||||
$translations = [];
|
||||
if ($langcodes > 0) {
|
||||
foreach($langcodes as $langcode) {
|
||||
$check_translation = $entity->getTranslation($langcode->getId());
|
||||
if ($check_translation !== NULL) {
|
||||
$translations[] = $entity->getTranslation($langcode->getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($translations as $translation) {
|
||||
|
||||
foreach ($source_field_names as $source_field_name) {
|
||||
foreach ($entity->$source_field_name as $fieldItem) {
|
||||
foreach ($translation->$source_field_name as $fieldItem) {
|
||||
$entity_data = [
|
||||
'bundle' => $media_entity_bundle,
|
||||
'uid' => $entity->getOwnerId(),
|
||||
'langcode' => $entity->language()->getId(),
|
||||
'langcode' => $fieldItem->getLangcode(),
|
||||
'status' => 1,
|
||||
];
|
||||
// Some entities (like taxonomy terms) do not have a an owner id
|
||||
if(method_exists($entity, 'getOwnerId')) {
|
||||
$entity_data['uid'] = $entity->getOwnerId();
|
||||
}
|
||||
|
||||
foreach (\array_keys($fieldItem->getValue()) as $subfield) {
|
||||
$entity_data[$media_target_field][$subfield] = $fieldItem->get($subfield)->getValue();
|
||||
|
@ -69,10 +84,9 @@ class MigrationHelperFieldTransformations {
|
|||
$media_target_ids[] = $media_entity->id();
|
||||
}
|
||||
}
|
||||
|
||||
$entity->set($media_field_name, $media_target_ids);
|
||||
$translation->set($media_field_name, $media_target_ids);
|
||||
}
|
||||
$entity->save();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue