I was trying to get a list of migrations with a certain tag, but if the tag didn't match anything it seems all migrations are returned, whereas I would expect no migrations to be returned.
So my code is doing:
$manager = \Drupal::service('plugin.manager.migration');
$plugins = $manager->createInstancesByTag($tag);
Which should filter the migrations, and does with migrations being found for an "valid" tag:
But for an invalid tag it returns all migrations which seems in error.
/**
* {@inheritdoc}
*/
public function createInstancesByTag($tag) {
$migrations = array_filter($this->getDefinitions(), function ($migration) use ($tag) {
return !empty($migration['migration_tags']) && in_array($tag, $migration['migration_tags']);
});
return $this->createInstances(array_keys($migrations));
}
So when $migrations is empty, which to my mind should return an empty array, the following code kicks in which seems to return all migrations for the plugin:
/**
* {@inheritdoc}
*/
public function createInstances($migration_id, array $configuration = []) {
if (empty($migration_id)) {
$migration_id = array_keys($this->getDefinitions());
}
So if I haven't missed something, the fix should be to return an empty array if the filter in createInstancesByTag finds nothing.