You are here

protected function MigrateManifest::injectDependencies in Migrate Manifest 8

Same name and namespace in other branches
  1. 8.2 src/MigrateManifest.php \Drupal\migrate_manifest\MigrateManifest::injectDependencies()
  2. 3.x src/MigrateManifest.php \Drupal\migrate_manifest\MigrateManifest::injectDependencies()

A naive graph flattener for compressing dependencies into a list.

Parameters

\Drupal\migrate\Plugin\MigrationInterface $migration:

\Drupal\migrate\Plugin\MigrationInterface[] $manifest_list:

Return value

\Drupal\migrate\Plugin\MigrationInterface[]

1 call to MigrateManifest::injectDependencies()
MigrateManifest::import in src/MigrateManifest.php
Drush execution method. Runs imports on the supplied manifest.

File

src/MigrateManifest.php, line 148

Class

MigrateManifest

Namespace

Drupal\migrate_manifest

Code

protected function injectDependencies(MigrationInterface $migration, array $manifest_list) {
  $migrations = [
    $migration
      ->id() => $migration,
  ];
  if ($required_ids = $migration
    ->get('requirements')) {

    /** @var \Drupal\migrate\Plugin\MigrationPluginManager $manager */
    $manager = \Drupal::service('plugin.manager.migration');

    /** @var \Drupal\migrate\Plugin\MigrationInterface[] $required_migrations */
    $required_migrations = [];
    foreach ($required_ids as $id) {

      // See if there are any configured versions of the migration already
      // in the manifest list.
      if (isset($manifest_list[$id])) {
        $required_migrations[$id] = $manifest_list[$id];
      }
      else {

        // TODO - add migrations to manifest list to avoid duplicate creation.
        $required_migrations = $manager
          ->createInstances($id) + $required_migrations;
      }
    }

    // Merge required migrations, using requirements as the base so they
    // bubble to the front.
    $migrations = $required_migrations + $migrations;

    // Recursively add and requirements the new migrations need.
    foreach ($required_migrations as $required_migration) {
      $migrations = $this
        ->injectDependencies($required_migration, $manifest_list) + $migrations;
    }
  }
  return $migrations;
}