Migrating Address Book in Drupal 8 Website Using Process Plugin
Migrating Address Book in Drupal 8 Website 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.
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.
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.
3: Create assets folder inside the module and paste your csv file inside it.
Prepare the csv as shown:
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 migrations 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.
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.