Overview of CMI in Drupal 8
There is three types of configuration data :
The Simple Configuration API
Used to store unique configuration object.
Are namespaced by the module_name.
Can contain a list of structured variables (string, int, array, ..)
Default values can be found in Yaml : config/install/module_name.config_object_name.yml
Have a schema defined in config/schema/module_name.schema.yml
Code example :
Not exportable, simple value that hardly depend of the environment.
Value can differ between environment (e.g. last_cron, maintenance_mode have different value on your local and on the production site)
The Entity Configuration API
Configuration object that can be multiple (e.g. views, image style, ckeditor profile, ...).
New Configuration type can be defined in custom module.
Have a defined schema in Yaml.
Values can be exported and stored as Yaml, can be stored by modules in config/install
Code example :
Store configuration object in the module :
Config object (not states) can be stored in a module and imported during the install process of the modules.
To export a config object in a module you can use the configuration synchronisation UI at /admin/config/development/configuration/single/export
Select the configuration object type, then the object, copy the content and store it in your custom module config/install directory following the name convention that is provided below the textarea.
You can also use the features module that is now a simple configuration packager.
If after the install of the module, you want to update the config object, you can use the following drush command :
Configuration override system
Remember the variable $conf in settings.php in D6/D7 for overriding variables.
In D8, you can also override variable from the configuration API:
You can also do overrides at runtime.
Example: getting a value in a specific languages :
Drupal provide a storage for override an module can specify her own way of override, for deeper informations look at :
The config object of Config API and of the configuration entity API have attached schema defined in module_name/config/install/module_name.schema.yml
These schema are not mandatory, but if you want to have translatable strings, nor form configuration / consistent export, you must take the time to implement the schema for your configuration object. However if you don't want to, you can just implement the toArray() method in your entity config object class.
Example, docs and informations : https://www.drupal.org/node/1905070
Configuration dependencies calculation
Default is in the .info of the module that define the config object like in D6/D7
But config entity can implements calculateDependencies() method to provide dynamic dependencies depending on config entity values.
Think of Config entity that store field display information for content entities specific view modes, there a need to have the module that hold the fields / formatters in dependencies but these are dynamic depending on the content entity display.
More information : https://www.drupal.org/node/2235409