In this series we'll be looking at Drupal 8 and many of its powerful features.
Today we'll be migrating structured taxonomy terms into a site using Drupal 8's core Migrate module and an associate contributed module called 'Migrate Source CSV'.
The aim here is to import/migrate a bunch of terms into a Drupal 8 site vocabulary using a relatively simple CSV file.
To start with we need five things:
- The 'Migrate' module enabled
- The 'Migrate Source CSV' module installed and enabled
- A CSV file containing our term data
- A configuration import script
- Drush to actually kick-off the migration import of the data
I'll skip steps 1 & 2 as they are standard module enabling steps.
3. The CSV file
Let's assume that we want to import a bunch of taxonomy terms into a vocabulary called 'my_vocab', as structured below:
We would create a normal CSV file (myterms.csv) that looks like this:
Once created save the 'myterms.csv' file to the sites pubic:// folder, which is defined in the 'File System' configuration page at '/admin/config/media/file-system'
4. The Configuration Import Script
Next, navigate to: Configuration / Configuration synchronization / Import / Single item (/admin/config/development/configuration/full/import)
Then under the 'Configuration type' dropdown, select 'Migration'
Paste in the following configuration script, and click the 'Import' button:
id: import_terms label: Migrate terms from the source CSV to taxonomy terms migration_group: migrated_terms source: plugin: csv path: public://myterms.csv header_row_count: 1 keys: - uuid column_names: 0: uuid: UUID 1: vid: VID 2: name: NAME 3: parent: PARENT destination: plugin: entity:taxonomy_term process: vid: vid name: name parent: plugin: migration migration: import_terms source: parent
5. The Drush command
Open up a command terminal and at your site root folder enter:
drush migrate-import import_terms
A list of available Drush Migrate commands can be found here: https://www.drupal.org/node/1561820
If you receive an error you may need to change the 'id' in order to run the drush migrate-import command again.
If successful you should receive a response indicating that 13 items were imported.