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:
- Configuration as YAML
- Possible to store in DB as well as files.
- 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
- Log-in to your site as a privileged user and Go to admin->configurations->configuration synchronize
- Here you will get 3 options Synchronize, Import and Export:
- Synchronize: Its compare the configuration uploaded to your sync directory with the active configuration before completing the import.
- Import: Upload a full/Single site configuration archive to the sync directory. It can then be compared and imported on the Synchronize page.
- Export: Export and download the full configuration of this site as a gzipped tar file.
- 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
- 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.
Import Configuration
- Login to your cloned site as a privileged user and again go to admin->configurations->configuration synchronization
- 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.
- 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.
- After checking all the changes you have to click on the “Import all” button below the list of changes.
- 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.
Benefits
- 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
- 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.
- 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
- Swappable: can store configuration in multiple formats like file, database, etc.
- 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.