Writing a custom migration source plugin
At this point, you have seen a few powerful ways that Drupal can migrate in data using available source plugins. What happens when one does not exist to meet your needs? You can write a migration source plugin, of course!
Consider this scenario. You need to migrate data in from a MySQL database as nodes into Drupal. While the migration system in Drupal can understand how to connect to databases, it does not understand how to query for the data you are trying to obtain. In these instances, you can write a source plugin.
How to do it…
Let’s assume that the database has a table named articles
that we want to pull data from in the migration, and it has id
, title
, body
, is_published
, and published_on
as fields. Before we can write our source plugin, the first thing we need to do is establish a connection that will access this database.
In your settings.php
file, add the following MySQL database connection:
$databases...