|
|
|
@ -1,10 +1,10 @@
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Drupal\agaric_migration_helpers;
|
|
|
|
|
namespace Drupal\migration_helpers;
|
|
|
|
|
|
|
|
|
|
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
|
|
|
|
|
|
|
|
|
class AgaricMigrationHelperFieldTransformations {
|
|
|
|
|
class MigrationHelperFieldTransformations {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The entity type manager.
|
|
|
|
@ -14,7 +14,7 @@ class AgaricMigrationHelperFieldTransformations {
|
|
|
|
|
protected $entityTypeManager;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructs an AgaricMigrationHelperFieldTransformations object.
|
|
|
|
|
* Constructs an MigrationHelperFieldTransformations object.
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(
|
|
|
|
|
EntityTypeManagerInterface $entity_type_manager
|
|
|
|
@ -50,29 +50,43 @@ class AgaricMigrationHelperFieldTransformations {
|
|
|
|
|
|
|
|
|
|
foreach ($entities as $entity) {
|
|
|
|
|
$media_target_ids = [];
|
|
|
|
|
|
|
|
|
|
foreach ($source_field_names as $source_field_name) {
|
|
|
|
|
foreach ($entity->$source_field_name as $fieldItem) {
|
|
|
|
|
$entity_data = [
|
|
|
|
|
'bundle' => $media_entity_bundle,
|
|
|
|
|
'uid' => $entity->getOwnerId(),
|
|
|
|
|
'langcode' => $entity->language()->getId(),
|
|
|
|
|
'status' => 1,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
foreach (\array_keys($fieldItem->getValue()) as $subfield) {
|
|
|
|
|
$entity_data[$media_target_field][$subfield] = $fieldItem->get($subfield)->getValue();
|
|
|
|
|
$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());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$media_entity = $media_entity_storage->create($entity_data);
|
|
|
|
|
$media_entity->save();
|
|
|
|
|
$media_target_ids[] = $media_entity->id();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$entity->set($media_field_name, $media_target_ids);
|
|
|
|
|
$entity->save();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
foreach ($translations as $translation) {
|
|
|
|
|
|
|
|
|
|
foreach ($source_field_names as $source_field_name) {
|
|
|
|
|
foreach ($translation->$source_field_name as $fieldItem) {
|
|
|
|
|
$entity_data = [
|
|
|
|
|
'bundle' => $media_entity_bundle,
|
|
|
|
|
'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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$media_entity = $media_entity_storage->create($entity_data);
|
|
|
|
|
$media_entity->save();
|
|
|
|
|
$media_target_ids[] = $media_entity->id();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$translation->set($media_field_name, $media_target_ids);
|
|
|
|
|
}
|
|
|
|
|
$entity->save();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|