X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fmigrate_drupal%2Fsrc%2FMigrationPluginManager.php;fp=web%2Fcore%2Fmodules%2Fmigrate_drupal%2Fsrc%2FMigrationPluginManager.php;h=0233de21a13c32f7e0de310545b88c16c23150f8;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/web/core/modules/migrate_drupal/src/MigrationPluginManager.php b/web/core/modules/migrate_drupal/src/MigrationPluginManager.php new file mode 100644 index 000000000..0233de21a --- /dev/null +++ b/web/core/modules/migrate_drupal/src/MigrationPluginManager.php @@ -0,0 +1,109 @@ +sourceManager = $source_manager; + $this->configFactory = $config_factory; + } + + /** + * Returns the migration tags that trigger source_module enforcement. + * + * @return string[] + */ + protected function getEnforcedSourceModuleTags() { + if ($this->enforcedSourceModuleTags === NULL) { + $this->enforcedSourceModuleTags = $this->configFactory + ->get('migrate_drupal.settings') + ->get('enforce_source_module_tags') ?: []; + } + return $this->enforcedSourceModuleTags; + } + + /** + * {@inheritdoc} + */ + public function processDefinition(&$definition, $plugin_id) { + parent::processDefinition($definition, $plugin_id); + + // If the migration has no tags, we don't need to enforce the source_module + // annotation property. + if (empty($definition['migration_tags'])) { + return; + } + + // Check if the migration has any of the tags that trigger source_module + // enforcement. + $applied_tags = array_intersect($this->getEnforcedSourceModuleTags(), $definition['migration_tags']); + if ($applied_tags) { + // Throw an exception if the source plugin definition does not define a + // source_module. + $source_id = $definition['source']['plugin']; + $source_definition = $this->sourceManager->getDefinition($source_id); + if (empty($source_definition['source_module'])) { + throw new BadPluginDefinitionException($source_id, 'source_module'); + } + } + } + +}