Migrating Address Book in Drupal 8 website using Process plugin

Category: Entertainment

Presentation Description

Migration can be done of many things like site migration, user migration, and content migration. Here, I will explain to migrate address book using Process plugin. Step-by-step address book migration using Process plugin. This Plugin allows you to process data within your company and pass it to a specified flow.


Presentation Transcript

slide 1:

Address Book Migration using Process plugin Migration is a term which all the developers who have started working in Drupal 8 have gone through once at least in their development cycle. Migration can be done of many things like site migration i.e migrate from Drupal 7 to Drupal 8 user migration content migration. In simple terms we can migrate all types of entity in Drupal 8. How this migration works: Migrate works by reading a row from a source plugin then running each property through a pipeline of process plugins thus resulting row to a destination plugin. Why we write process plugin Each process plugin gets the current value and returns a value. Here we are going to look how this process plugin works. We are going to migrate Address fields using process plugin in Drupal 8. Follow the below steps. 1: Install the following modules 1. Migrate Tools 2. Migrate plus 3. Migrate Source CSV 2: Create a custom module. ‘custom_addressbook_migration’ Create a .info file script src"https://gist.github.com/Rajeshwari21/de0999a1fa45eea342e0c673bf9793ef.js"/sc ript 3: Create assets folder inside the module and paste your csv file inside it. Prepare the csv as shown:

slide 2:

4: Create process Plugin Add a new plugin class called AddressFieldMigration in your module at src/Plugin/migrate/process/AddressFieldMigration.php. The MigrateProcessPlugin annotation tells migrate about the new process plugin and the id key is used to select this plugin in a migration’s mappings. The class should extend Drupal\migrate\ProcessPluginBase and override the transform method. This method will be passed to the incoming source value and is responsible for returning the modified destination value. script src"https://gist.github.com/Rajeshwari21/37d249224f421f80afe6b57322577306.js"/sc ript Here in Csv we are passing the country name but address requires country code so we have made use of CountryManager Class to get the country code from given country name. We get the region names in form of code mostly for Foreign Countries In the csv you can see it is given as ‘CA’. So to get the state name we have to make use of methods from SubdivisionRepository Class. 5: Now we have to create a Migrate Configuration file and import this configuration. Create the configuration file as shown: script src"https://gist.github.com/Rajeshwari21/39f6819ee457ef5b4998d0c81ea40e01.js"/script Here • Address is created under profile entity so the destination plugin name is entity:profile. • Process plugin is written to map all the columns given in source csv file to its respective fields in address entity. In Migration always we have to mention the source destination and process.

slide 3:

6: Import the Above configuration file into drupal site. • Goto admin config development configuration • Click on Import Tab and Choose Single Item • Select the Configuration Type as Migration • Paste the above configuration file and click on Import. 7: Drush Commands to implement • drush ms - you will see the status of all the migrations. • drush mi address_fields_migration. 8: Conclusion: Now Go to admin config people profiles and you will see list of address that have been migrated. This is how address fields are migrated using process plugin in drupal 8. To know more about migration using Process plugin Refer Drupal 8 Process Plugin Since I have mentioned only few drush commands related to migration you can check more about this Here Please put your doubts suggestions or queries related to above topic in the below comment box and I will try to answer them.

authorStream Live Help