CMI: The new backbone of Drupal 8

This is my first blog for Drupal 8. I didn’t work on Drupal 8 before joined my new company and they have given me first chance to start work on Drupal 8. I had join a session on CMI in Nov 2016 (at Aquia office CP), which is given by Neetu morwani, and that was my first time when i heard about CMI. Now this time i have given my first session on CMI (Configuration management system) and start writing my first blog on it.

CMI: Configuration management system

CMI is an initiative, when people start work on Drupal 8, so somebody has taken this initiative to build a powerful configuration system to import and export setting of any website without any interference, called Greg Dunlap, IRC: heyrocker. Now this CMI system has their own IRC channel called drupal-cmi, where people can discuss their issues/suggestions.

CMI in D8

Configuration in D8 means breaking of information:

  1. Configuration as YAML
  2. Possible to store in DB as well as files.
  3. Drupal 8 CMI is pluggable with various storage systems. (could be stored in memcache/ redis for even quicker access).


Step to import and export configuration:

The first condition for import and export configuration in Drupal 8 is both the instance is cloned of each-other.

Export configuration

  1. Log-in to your site as a privileged user and Go to admin->configurations->configuration synchronize
  2. Here you will get 3 options Synchronize, Import and Export:
    1. Synchronize: Its compare the configuration uploaded to your sync directory with the active configuration before completing the import. 
    2. Import: Upload a full/Single site configuration archive to the sync directory. It can then be compared and imported on the Synchronize page.
    3. Export: Export and download the full configuration of this site as a gzipped tar file.
  3. Now click on the export tab and choose single or full export options after that click on the export button. Let say we have chosen full export 
  4. After click on the export button, it will download a tar.gz file e.g abc.tar.gz. This file contains all the exported configuration in YML format.
    export config setting

 

Import Configuration

  1. Login to your cloned site as a privileged user and again go to admin->configurations->configuration synchronization
  2. Here you will get 3 options and just click on the Import tab, now you will have to choose whether you want to import single configuration or full configuration.
    Import option
  3. After importing the tar.gz file it will show you all the change and with the ‘View differences’ button by clicking on this button you can check the difference before and after import.
    check differences
  4. After checking all the changes you have to click on the “Import all” button below the list of changes.
    import all button
  5. When you click on the Import all button it starts to import all the configuration setting. After finishing this part you will get all your changes in your instance.
    start importing configuration setting

 

Benefits

  1. Eliminated 50 database table or more.: Yes lots of tables have been removed from Drupal 8 as like in Drupal 7 have their own variable table, a separate table for views but in Drupal 8, CMI has their own table in which every setting stored in this table like all variables, views, etc 
  2. Reduced need for features: at the time of writing this article Feature is not ported to Drupal 8 but in future, it will and which is fully depended on CMI.

  3. Translate configuration: The best part of CMI is anything can be translated to another language and it’s also possible in CMI. Any configuration setting can be translated to other languages on the same instance 

  4. Swappable: can store configuration in multiple formats like file, database, etc.

  5. API for developers: CMI provides API to the developers so that they can extend the CMI according to their own way.

 

Drush love's CMI(Configuration management)

Config commands:

  • config-edit (cedit): Open a config file in a text editor. Edits are imported into active configuration after closing editor.
  • config-export (cex): Export configuration to a directory.
  • config-get (cget): Display a config value or a whole configuration object.
  • config-import (cim): Import config from a config directory.
  • config-list (cli): List config names by the prefix.
  • config-pull (cpull): Export and transfer config from one environment to another.
  • config-set (cset): Set config value directly.