diff -u b/migrate_plus.module b/migrate_plus.module --- b/migrate_plus.module +++ b/migrate_plus.module @@ -5,16 +5,8 @@ * Provides tools and enhancements for implementing and managing migrations. */ -/** - * Implements hook_entity_type_alter(). - */ -function migrate_plus_entity_type_alter(array &$entity_types) { - // Substitute our own classes to provide enhanced functionality to the - // migration entity type. - /** @var \Drupal\Core\Config\Entity\ConfigEntityType[] $entity_types */ - $entity_types['migration'] - ->setHandlerClass('storage', 'Drupal\migrate_plus\MigrationStorage'); -} +use Drupal\migrate\Entity\MigrationInterface; +use Drupal\migrate_plus\Entity\MigrationGroupInterface; /** * Implements hook_config_schema_info_alter(). @@ -30,0 +23,36 @@ + +/** + * Implements hook_ENTITY_TYPE_load(). + */ +function migrate_plus_migration_load($migrations) { + /** @var MigrationInterface $migration */ + foreach ($migrations as $migration) { + // If we are pointing to a valid group, merge its properties into ours. + if (isset($migration->migration_group)) { + /** @var MigrationGroupInterface $group */ + $group = entity_load('migration_group', $migration->migration_group); + if ($group) { + $shared_configuration = $group->get('shared_configuration'); + if ($shared_configuration) { + foreach ($shared_configuration as $key => $group_value) { + $migration_value = $migration->get($key); + // Where both the migration and the group provide arrays, + // replace recursively (so each key collision is resolved in favor + // of the migration). + if (is_array($migration_value) && is_array($group_value)) { + $merged_values = array_replace_recursive($group_value, $migration_value); + $migration->set($key, $merged_values); + } + // Where the group provides a value the migration doesn't, use + // the group value. + elseif (is_null($migration_value)) { + $migration->set($key, $group_value); + } + // Otherwise, the existing migration value overrides the group + // value. + } + } + } + } + } +} reverted: --- b/src/MigrationStorage.php +++ /dev/null @@ -1,103 +0,0 @@ -migrationGroupStorage = $migration_group_storage; - } - - /** - * {@inheritdoc} - */ - public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { - return new static( - $entity_type, - $container->get('config.factory'), - $container->get('uuid'), - $container->get('language_manager'), - $container->get('entity.manager')->getStorage('migration_group') - ); - } - - /** - * {@inheritdoc} - */ - protected function doLoadMultiple(array $ids = NULL) { - $migrations = parent::doLoadMultiple($ids); - - /** @var MigrationInterface $migration */ - foreach ($migrations as $migration) { - // If we are pointing to a valid group, merge its properties into ours. - if (isset($migration->migration_group)) { - /** @var MigrationGroupInterface $group */ - $group = $this->migrationGroupStorage->load($migration->migration_group); - if ($group) { - $shared_configuration = $group->get('shared_configuration'); - if ($shared_configuration) { - foreach ($shared_configuration as $key => $group_value) { - $migration_value = $migration->get($key); - // Where both the migration and the group provide arrays, - // replace recursively (so each key collision is resolved in favor - // of the migration). - if (is_array($migration_value) && is_array($group_value)) { - $merged_values = array_replace_recursive($group_value, $migration_value); - $migration->set($key, $merged_values); - } - // Where the group provides a value the migration doesn't, use - // the group value. - elseif (is_null($migration_value)) { - $migration->set($key, $group_value); - } - // Otherwise, the existing migration value overrides the group - // value. - } - } - } - } - } - return $migrations; - } - -}