Skip to content

Instantly share code, notes, and snippets.

@dinarcon
Created August 15, 2017 02:22
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dinarcon/b4e250e40d9e6eff15b850ed5b52535f to your computer and use it in GitHub Desktop.
Save dinarcon/b4e250e40d9e6eff15b850ed5b52535f to your computer and use it in GitHub Desktop.
Drupal 8 migrations by example
Professor ID Title Author
P01 The pushcart war Jean Merrill
P02 The definite guide to Drupal 7 Benjamin Melançon et al.
P03 The five love languages Gary Chapman
Professor ID Photo URL
P01 sites/default/files/pictures/picture-2-1421176752.jpg
P02 sites/default/files/pictures/picture-3-1421176784.jpg
P03 sites/default/files/pictures/picture-15-1421176712.jpg
Professor ID First Name Last Name Department Date City State ZIP Country Code Biography
P01 Stefan Freudenberg Physics July 17, 2006 Hamburg 21073 DE Part analyst, part troubleshooter, and part troublemaker, Stefan serves as Agaric's <em>secret weapon</em> and resident heretic.
P02 Benjamin Melançon Journalism August 12, 2008 Minneapolis MN 55111 US Benjamin lives and works to <strong>connect people, ideas, and resources</strong> so more awesome things happen.
P03 Michele Metts Law September 12, 2010 Boston MA 02111 US Michele Metts has been a involved with <a href=”http://drupal.org”>Drupal</a> since 2006.
id: mbe_book_paragraph
label: 'Import book paragraph'
source:
plugin: csv
path: ../migrate/mbe_book_paragraph.csv
header_row_count: 1
keys:
- 'Professor ID'
process:
field_mbe_title: Title
field_mbe_author: Author
destination:
plugin: 'entity_reference_revisions:paragraph'
default_bundle: mbe_book
migration_dependencies: null
id: mbe_photo_field
label: 'Import photos of professors'
source:
constants:
SOURCE_BASE_PATH: 'http://agaric.com'
DRUPAL_FILE_DIRECTORY: 'public://professor_photo'
plugin: csv
path: ../migrate/mbe_photos.csv
header_row_count: 1
keys:
- 'Professor ID'
process:
destination_filename:
-
plugin: callback
callable: basename
source: 'Photo URL'
-
plugin: skip_on_empty
method: row
destination_full_path:
-
plugin: concat
delimiter: /
source:
- constants/DRUPAL_FILE_DIRECTORY
- '@destination_filename'
-
plugin: urlencode
source_full_path:
-
plugin: concat
delimiter: /
source:
- constants/SOURCE_BASE_PATH
- 'Photo URL'
-
plugin: urlencode
uri:
plugin: file_copy
source:
- '@source_full_path'
- '@destination_full_path'
destination:
plugin: 'entity:file'
migration_dependencies: null
label: 'Import professors'
source:
plugin: csv
path: ../migrate/mbe_professors.csv
header_row_count: 1
keys:
- 'Professor ID'
process:
type:
plugin: default_value
default_value: mbe_professor
title:
plugin: concat
source:
- 'First Name'
- 'Last Name'
delimiter: ' '
field_mbe_biography/value: Biography
field_mbe_biography/format:
plugin: default_value
default_value: basic_html
field_mbe_department:
plugin: entity_generate
source: Department
entity_type: taxonomy_term
bundle: mbe_department_vocabulary
value_key: name
bundle_key: vid
field_mbe_photo/target_id:
plugin: migration_lookup
migration: mbe_photo_field
source: 'Professor ID'
field_mbe_photo/alt:
plugin: default_value
default_value: 'Professor headshot'
mbe_book_paragraph:
plugin: migration
migration: mbe_book_paragraph
source: 'Professor ID'
field_mbe_favorite_books:
plugin: iterator
source:
- '@mbe_book_paragraph'
process:
target_id: '0'
target_revision_id: '1'
field_mbe_experience_date:
plugin: format_date
source: Date
from_format: 'F d, Y'
to_format: Y-m-d
timezone: America/Managua
field_mbe_coworking_address/address_line1:
plugin: default_value
default_value: 'It is a secret ;)'
field_mbe_coworking_address/locality: City
field_mbe_coworking_address/administrative_area: State
field_mbe_coworking_address/postal_code: ZIP
field_mbe_coworking_address/country_code: 'Country Code'
destination:
plugin: 'entity:node'
migration_dependencies:
required:
- mbe_photo_field
- mbe_book_paragraph
optional: { }
@summitims
Copy link

Hi, doesn't this example need a info yml file to get it working? And is it Drupal 10 compatible? Greetings,

@dinarcon
Copy link
Author

@summitims the full example modules are available at https://github.com/dinarcon/ud_migrations and blog posts with the explanations at https://understanddrupal.com/courses/31-days-of-migrations/

I have not added D10 compatibility yet. I expect minimal changes are necessary, but I have not have a chance to do it yet. Keep an eye on the repo and on the site for updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment