migrate.api.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /**
  3. * @file
  4. * Hooks provided by the Migrate module.
  5. */
  6. use Drupal\migrate\Plugin\MigrationInterface;
  7. use Drupal\migrate\Plugin\MigrateSourceInterface;
  8. use Drupal\migrate\Row;
  9. /**
  10. * @defgroup migration Migration API
  11. * @{
  12. * Overview of the Migration API, which migrates data into Drupal.
  13. *
  14. * @section overview Overview of migration
  15. * Migration is an
  16. * @link http://wikipedia.org/wiki/Extract,_transform,_load Extract, Transform, Load @endlink
  17. * (ETL) process. In the Drupal migration API the extract phase is called
  18. * "source", the transform phase is called "process", and the load phase is
  19. * called "destination". It is important to understand that the "load" in ETL
  20. * means to load data into storage, while traditionally Drupal uses "load" to
  21. * mean load data from storage into memory.
  22. *
  23. * Source, process, and destination phases are each provided by plugins.
  24. * Source plugins extract data from a data source in "rows", containing
  25. * "properties". Each row is handed off to one or more process plugins which
  26. * transform the row's properties. After all the properties are processed, the
  27. * resulting row is handed off to a destination plugin, which saves the data.
  28. *
  29. * A source plugin, one or more process plugins, and a destination plugin are
  30. * brought together to extract, transform, and load (in the ETL sense) a specific
  31. * type of data by a migration plugin.
  32. *
  33. * @section sec_migrations Migration plugins
  34. * Migration plugin definitions are stored in a module's 'migrations' directory.
  35. * For backwards compatibility we also scan the 'migration_templates' directory.
  36. * Examples of migration plugin definitions can be found in
  37. * 'core/modules/action/migration_templates'. The plugin class is
  38. * \Drupal\migrate\Plugin\Migration, with interface
  39. * \Drupal\migrate\Plugin\MigrationInterface. Migration plugins are managed by
  40. * the \Drupal\migrate\Plugin\MigrationPluginManager class.
  41. *
  42. * @section sec_source Source plugins
  43. * Migration source plugins implement
  44. * \Drupal\migrate\Plugin\MigrateSourceInterface and usually extend
  45. * \Drupal\migrate\Plugin\migrate\source\SourcePluginBase. They are annotated
  46. * with \Drupal\migrate\Annotation\MigrateSource annotation, and must be in
  47. * namespace subdirectory Plugin\migrate\source under the namespace of the
  48. * module that defines them. Migration source plugins are managed by the
  49. * \Drupal\migrate\Plugin\MigratePluginManager class.
  50. *
  51. * @section sec_process Process plugins
  52. * Migration process plugins implement
  53. * \Drupal\migrate\Plugin\MigrateProcessInterface and usually extend
  54. * \Drupal\migrate\ProcessPluginBase. They are annotated
  55. * with \Drupal\migrate\Annotation\MigrateProcessPlugin annotation, and must be
  56. * in namespace subdirectory Plugin\migrate\process under the namespace of the
  57. * module that defines them. Migration process plugins are managed by the
  58. * \Drupal\migrate\Plugin\MigratePluginManager class. The Migrate module
  59. * provides process plugins for common operations (setting default values,
  60. * mapping values, etc.).
  61. *
  62. * @section sec_destination Destination plugins
  63. * Migration destination plugins implement
  64. * \Drupal\migrate\Plugin\MigrateDestinationInterface and usually extend
  65. * \Drupal\migrate\Plugin\migrate\destination\DestinationBase. They are
  66. * annotated with \Drupal\migrate\Annotation\MigrateDestination annotation, and
  67. * must be in namespace subdirectory Plugin\migrate\destination under the
  68. * namespace of the module that defines them. Migration destination plugins
  69. * are managed by the \Drupal\migrate\Plugin\MigrateDestinationPluginManager
  70. * class. The Migrate module provides destination plugins for Drupal core
  71. * objects (configuration and entity).
  72. *
  73. * @section sec_more_info More information
  74. * @link https://www.drupal.org/node/2127611 Migration API documentation. @endlink
  75. *
  76. * @see update_api
  77. * @}
  78. */
  79. /**
  80. * @addtogroup hooks
  81. * @{
  82. */
  83. /**
  84. * Allows adding data to a row before processing it.
  85. *
  86. * For example, filter module used to store filter format settings in the
  87. * variables table which now needs to be inside the filter format config
  88. * file. So, it needs to be added here.
  89. *
  90. * hook_migrate_MIGRATION_ID_prepare_row() is also available.
  91. *
  92. * @ingroup migration
  93. */
  94. function hook_migrate_prepare_row(Row $row, MigrateSourceInterface $source, MigrationInterface $migration) {
  95. if ($migration->id() == 'd6_filter_formats') {
  96. $value = $source->getDatabase()->query('SELECT value FROM {variable} WHERE name = :name', array(':name' => 'mymodule_filter_foo_' . $row->getSourceProperty('format')))->fetchField();
  97. if ($value) {
  98. $row->setSourceProperty('settings:mymodule:foo', unserialize($value));
  99. }
  100. }
  101. }
  102. /**
  103. * @} End of "addtogroup hooks".
  104. */