One of the more interesting aspects of the extensive Drupal overhaul that came with the Drupal 8 update, was the file-base configuration management system. While settings are stored in the database of a Drupal website, with Drupal 8 those settings and configurations can now be automatically exported and save as files within the Drupal installations file system.

This opens up many new possibilities, not the least of which is an easier way to move settings and configuration between versions of your Drupal website, and even store that configuration within version control systems like Git.

Here is a video of one of the original introductions of the system at the Austin DrupalCon in 2014.

One issue that people might encounter while working with new module development, especially migrations, and the configurations that those modules use and generate, is the loading of the changed configurations while continuously developing said modules.

By default, most configurations are loaded at the time a module is enabled, so if you are actively developing and testing a module you will need to trigger this to get the latest configuration. This is especially relevant for custom Drupal migrations since the development process can often be very iterative as you map out the fields and content types you are migrating for your Drupal 8 website.

In the past, clearing your Drupal website cache might have been enough to ensure that new functions or classes were discovered so that you could re-test your migration script. But now that migration configurations are set up in YAML files for the configuration management system, it might become tedious to be constantly reinstalling your module in order to test new changes to your migration script.

Since Monarch Digital works on a lot of Drupal 8 migrations, from Drupal 6 or even Drupal 7, we spent a few minutes developing a simple custom Drush script to streamline this process for us. This Drush script, which you can just add the file of to your custom Drupal module or migration module, will simultaneously rebuild your cache and reinstall the designated module that you specify. And since currently the Drush command line interface is generally the preferred way to manage your Drupal 8 migration scripts, you’ll be right there already.

Hopefully, this little drush script will save you some time and make your Drupal 8 migration development somewhat easier!

 

<?php
 
/**
 * @file (your_custom_module.drush.inc)
 * Command-line tools to aid migrations.
 */
 
use Drush\Log\LogLevel;
 
/**
 * Implements hook_drush_command().
 */
function config_migrate_drush_command() {
  $items['config-migrate-reload'] = [
    'description' => 'Reload custom migration configurations.',
    'options' => [],
    'arguments' => [],
    'examples' => [
      'config-migrate-reload' => 'Reload all custom migration configurations.',
    ],
    'drupal dependencies' => ['your_custom_migrate_module'],
    'aliases' => ['cmr'],
  ];
 
  return $items;
}
 
/**
 * Reload custom migration configurations.
 *
 * @see config_migrate_drush_command().
 */
function drush_config_migrate_reload() {
  // Uninstall and reinstall all configuration.
  \Drupal::service('config.manager')->uninstall('module', 'your_custom_migrate_module');
  \Drupal::service('config.installer')->installDefaultConfig('module', 'your_custom_migrate_module');
  drush_log(dt('Config reload complete.'), LogLevel::OK);
 
  // Rebuild caches.
  drush_invoke('cache-rebuild');
}

If you have any questions about how this code works or ways you can modify it to suit your specific needs, please don't hesitate to contact us! See the contact form below.