DEV Community

Cover image for Managing configuration objects in Drupal 8|9 for Migrations
David Rodríguez
David Rodríguez

Posted on • Edited on

Managing configuration objects in Drupal 8|9 for Migrations

Introduction

Well, I was working in some migrations and I thought that it would be interesting to gather some tools for working with configuration objects, especially from the point of view of Drupal migrations based on a treatment as configuration (not as code).

You can learn the differences between both approaches (Migration as code or Migration as configuration) in this article: https://www.therussianlullaby.com/blog/thinking-about-drupal-migrations-examples.

But maybe the most important point right now it's that if you decide to manage a Drupal Migration as a Configuration entity, then, you'll create a new active configuration Object in your Drupal Installation. This change all the whole workflow of a single migration as code, due to (now), you're putting your new migration inside the processes and workflows of the Configuration Management System of Drupal. Ok? Let's see.

I'm working in a basic migration example using a classical .csv file as datasource. I'm building the basic scaffolding in a custom module, with the next structure:

/project/web/modules/custom/  
                     \__migration_csv_module/  
                         \__migration_csv_module.info.yml
                          \__csv/
                               \_migration_csv_articles.csv
                           \__config/
                              \__install/
                                 \__migrate_plus.migration.csv_import.yml

In order to run the migration using drush commands for migrations, First I will have to load the new active configuration object. Ok.

You can use the User Interface in path:
/admin/config/development/configuration/single/export

Loading a migration config object

And finally, if I decide stop the migration and delete the results, I have to eliminate this config object. Let's see some tactics.

Auto delete the active config object

When you're working with Drupal migrations as config, then you have to ensure the delete of the new migration-related config object in your Drupal System. You have to declare your own custom module as a forced dependency of the migration, and so when you disabled the module, then this config object will disappear.

I mean: file migrate_plus.migration.article_csv_import.yml

with content:

uuid: 1bcec3e7-0a49-4473-87a2-6dca09b91aba
id: article_csv_import
label: 'Migrating articles'
langcode: en
status: true
dependencies:
  enforced:
    module:
      - migration_csv_module

Reviewing configuration objects

You can use this contrib module in order to test and review config:

Configuration Inspector Module.

I didn't know it, but in the context of this issue, Pedro Cambra recommended me to use it. With this module you'll can review a config:

Configuration Inspector Module Feedback

Deleting configuration objects

Also you can use the classical tools from drush and drupal console (both are Drupal CLIs) in order to delete some config objects.

Using drush

:~$ drush config-delete 'migrate_plus.migration.csv_import'

:~$ drush config:delete "migrate_plus.migration.csv_import"

:~$ drush cdel migrate_plus.migration.csv_import

Using Drupal Console

:~$ drupal config:delete active "mymigration.active_config_object"

:~$ drupal cd active mymigration.active_config_object

You can use this contrib module from Goran Nikolovski:

Config Delete Module.

Just install this module and visit the following page:

/admin/config/development/configuration/delete

Then you'll be able to select the Config Object and delete it.

Top comments (0)