Problem/Motivation
In discussing the test module for a CSV source plugin for migrations, which was breaking for him but not for me, @phenaproxima and I realized it was breaking on Drupal source-specific stuff (applyCckFieldProcessors()) in Drupal\migrate_drupal\MigrationStorage because he had migrate_drupal enabled but I didn't. The problem:
function migrate_drupal_entity_type_alter(array &$entity_types) {
/** @var \Drupal\Core\Config\Entity\ConfigEntityType[] $entity_types */
$entity_types['migration']
->setClass('Drupal\migrate_drupal\Entity\Migration')
->setHandlerClass('storage', 'Drupal\migrate_drupal\MigrationStorage');
}
I.e., when migrate_drupal is enabled, it injects its own Migration and MigrationStorage classes in place of those in Drupal\migrate. And those classes, which provide functionality specific to migrate_drupal, will also be used for any non-migrate_drupal migrations. Not good. hook_entity_type_alter() should only be used when the type needs to be altered globally - i.e., when adding functionality that applies to all instances of the type. It is not an appropriate mechanism for a module to add functionality specific to its own needs.
Proposed resolution
Not quite sure at the moment...
Remaining tasks
TBD
User interface changes
N/A
API changes
TBD
Comments
Comment #1
mikeryan@benjy: You would need the latest migrate_plus patches from #2458003: Port MigrateSourceCSV to Drupal 8 migrate source plugin and #2451331: Add documentation to People example migration in migrate_source_csv_test. If you then enable migrate_drupal before enabling migrate_example_baseball, it all goes to hell.
This is the case we ran into, but beyond that pretty much any non-migrate_drupal migration is going to break if you have migrate_drupal enabled.
Comment #2
phenaproximaAs per discussion on IRC today, a possible solution emerged.
The reason migrate_drupal is hijacking these classes is primarily to deal with dynamic migrations (load plugins) -- especially migrations dealing with CCK fields. Once #2463909: Migrations should support non-installed default configurations (templates) lands, we will be implementing a new plugin type (which I've tentatively named "generators") which will replace load plugins by pre-generating migrations that need to be dynamic, from templates. Once that's all done, migrate_drupal's Migration and MigrationStorage classes will no longer be of use (because load plugins will be a thing of the past) and can be safely removed.
Comment #3
mikeryan#2507607: [META] Replace Cthulhu-forsaken load plugins with migration builders is the avenue we're pursuing to fix this (and other things).
Comment #4
phenaproximaThis will be fixed implicitly by #2549013: Remove load plugins, so there is no need for a separate issue.