You are here

public function MigrateLookup::lookup in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/migrate/src/MigrateLookup.php \Drupal\migrate\MigrateLookup::lookup()

Retrieves destination ids from a migration lookup.

Parameters

string|string[] $migration_ids: An array of migration plugin IDs to look up, or a single ID as a string.

array $source_id_values: An array of source id values.

Return value

array An array of arrays of destination ids, or an empty array if none were found.

Throws

\Drupal\Component\Plugin\Exception\PluginException Thrown by the migration plugin manager on error, or if the migration(s) cannot be found.

\Drupal\migrate\MigrateException Thrown when $source_id_values contains unknown keys, or is the wrong length.

Overrides MigrateLookupInterface::lookup

File

core/modules/migrate/src/MigrateLookup.php, line 35

Class

MigrateLookup
Provides a migration lookup service.

Namespace

Drupal\migrate

Code

public function lookup($migration_id, array $source_id_values) {
  $results = [];
  $migrations = $this->migrationPluginManager
    ->createInstances($migration_id);
  if (!$migrations) {
    if (is_array($migration_id)) {
      if (count($migration_id) != 1) {
        throw new PluginException("Plugin IDs '" . implode("', '", $migration_id) . "' were not found.");
      }
      $migration_id = reset($migration_id);
    }
    throw new PluginNotFoundException($migration_id);
  }
  foreach ($migrations as $migration) {
    if ($result = $this
      ->doLookup($migration, $source_id_values)) {
      $results = array_merge($results, $result);
    }
  }
  return $results;
}