XML-D8 Migration: Extending the migration capabilities by using CUSTOM Process plugin
In our last blog post, XML-D8 Migration: Extending the migration capabilities by using available Process plugins, we have extended the migration capabilities by using already available process plugins. In this blog post, we will extend the capabilities of that migration by writing custom Process plugins.
In this blog post, we will map the content to different content types based on the 'site url' field in XML. There are no changes in XML file and we are using the same XML file which was used in earlier blog posts.
To use the custom plugin, we need to specify the plugin name in our .yml file under config/install, so we have made that one change which looks below,
Basically we are telling the migration API that for 'type' field use 'content_type_plugin' and 'site_url' XML field will be used as source.
Next we have created the custom process plugin in src/Plugin/migrate/process/ContentTypePlugin.php. This custom process plugin uses 'site_url' XML field to determine the content type (article or basic page) based on the requirements. Custom process plugin needs to be placed under /src/Plugin/migrate/process/ as per the Drupal PSR-4 standards. The plugins in Drupal 8 uses Annotations to define the name of the plugin. Our custom plugin looks like below,
After creating the custom process plugin and using it in our migration config .yml file, we need to clear the cache and re-install the module. And finally we can execute the migration to migrate the XML data in Drupal content types (article, page).
The migration has been executed successfully and we got all the data on D8 site in different content types as expected. It looks like below,
The source code is also available on Git repository.
Similarly we can write more custom process plugins based on our requirements and use them to do custom migrations!
In this blog post, we will map the content to different content types based on the 'site url' field in XML. There are no changes in XML file and we are using the same XML file which was used in earlier blog posts.
To use the custom plugin, we need to specify the plugin name in our .yml file under config/install, so we have made that one change which looks below,
Basically we are telling the migration API that for 'type' field use 'content_type_plugin' and 'site_url' XML field will be used as source.
Next we have created the custom process plugin in src/Plugin/migrate/process/ContentTypePlugin.php. This custom process plugin uses 'site_url' XML field to determine the content type (article or basic page) based on the requirements. Custom process plugin needs to be placed under /src/Plugin/migrate/process/ as per the Drupal PSR-4 standards. The plugins in Drupal 8 uses Annotations to define the name of the plugin. Our custom plugin looks like below,
After creating the custom process plugin and using it in our migration config .yml file, we need to clear the cache and re-install the module. And finally we can execute the migration to migrate the XML data in Drupal content types (article, page).
The migration has been executed successfully and we got all the data on D8 site in different content types as expected. It looks like below,
The source code is also available on Git repository.
Similarly we can write more custom process plugins based on our requirements and use them to do custom migrations!




Comments