This document discusses how to write dynamic migrations in Drupal 8 using migration templates and derivers. Derivers allow migrations to be generated dynamically based on configurable inputs. They work by extending the DeriverBase class and implementing the getDerivativeDefinitions() method to define how derivative migrations are generated. Migration templates provide a flexible way to create migrations and derivers can be specified in the template file to dynamically generate migrations. Examples of where this approach is used include migrating sites with different languages/attributes and migrating content between Drupal versions.
5. 5axelerant.com
Migrations: A brief introduction
What Migrate API Provides:
● Migrate Data from source to destination
● Keeps track of record of migrated data
● Provides framework for writing migrations
8. 8axelerant.com
Understanding Derivatives
● Drupal 7 has “_info()” hooks
● Wonder how do we generate multiple blocks with single block plugin ?
● Drupal 8 has “Derivatives”
● Allows to generate instances dynamically
14. 14axelerant.com
Migration as Configuration entities
● Similar to any configurations
● Resides in [module]/config directory
● Typically names are given like “migrate.migration.node_page.yml”
15. 15axelerant.com
Migration as Configuration entities
Advantages:
● Easy to write and run
● No need to write specific logic to run unlike migration templates
Disadvantages:
● Not much flexible
● Hard to change runtime
● Dynamic migration generation is not possible
● Can’t generate based on user inputs
16. 16axelerant.com
Migration as templates
● Resides in [module]/migration_templates directory
● Names could match the migration id
● Typically names are given like “node_page.yml”
17. 17axelerant.com
Migration as templates
Advantages:
● Much more flexible than configuration entities for each variation
● Easy to change runtime
● Ability to generate dynamic migration using reusable templates
22. 22axelerant.com
Use cases
● Migrating large amount of sites with similar architecture
but different languages in each site (our use case,
https://github.com/miteshmap/drupal_migration_demo)
● Core: Migrating D7 to D8
● Core: Migrating Workbench Moderation to Content
Moderation (https://www.drupal.org/project/wbm2cm)
● Migrating sites from Magento for instance with different
attributes for each site
● And many more...
23. 23axelerant.com
Thank you … for being here and allowing
us to contribute and share our knowledge
To summarise…
● We discussed how to make migrations more dynamic and
less painful
● We saw an example of how to write derivers
● We saw advantages of doing it, it is done in Core and many
contrib modules already