You are here

function migrate_plus_migration_load in Migrate Plus 8

Implements hook_ENTITY_TYPE_load().

File

./migrate_plus.module, line 18
Provides enhancements for implementing and managing migrations.

Code

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.
    $migration_group = $migration
      ->getThirdPartySetting('migrate_plus', 'migration_group');
    if (empty($migration_group)) {
      $migration_group = 'default';
    }
    $group = MigrationGroup::load($migration_group);
    if (empty($group)) {
      continue;
    }
    $shared_configuration = $group
      ->get('shared_configuration');
    if (empty($shared_configuration)) {
      continue;
    }
    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);
      }
      elseif (is_null($migration_value)) {
        $migration
          ->set($key, $group_value);
      }

      // Otherwise, the existing migration value overrides the group
      // value.
    }
  }
}