Drupal 8 introduced a new API to centralize the storage and accessing of configuration information. This replaces the existing system of variable_get()/variable_set() as well as many one-off storage systems like the ones used for image styles.
The configuration system employs a three-level architecture:
Level 1: Signed file storage
At the lowest level, all configuration data will be stored on-disk using files in serialized format that is both machine and human readable.
Individual configuration files (
prefix.example.yml) will look like the following:
some_string: 'Woo kittens!'
Level 2: Active Store
This layer moves the configuration data from the file system to something that can be read and accessed much more readily. For the vast majority of Drupal sites this will be database storage, but for high-performance sites could be something like MongoDB or Redis. This is called the “active store.”
In the default configuration, this will push data into a central table called "config":
CREATE TABLE config (
name varchar(255) NOT NULL DEFAULT '' COMMENT 'The identifier for the configuration entry, such as module.example (the name of the file, minus .yml).',
data longtext NOT NULL COMMENT 'The raw YAML data for this configuration entry.',
PRIMARY KEY (name),
All site configuration data gets read out of this. The data here gets updated on two conditions:
- UI changes (automatic): When the save button is clicked on an admin page, data gets written to both the active store and the .yml file from layer 1 (the digital signatures for the changed file gets regenerated).
- Code changes (manual): When migrating configuration from dev to prod, for example, the underlying files will have changed, but the data in the database table will not. Data will continue to be read from the active store so that the site doesn't break. Site admins can replace the contents of the active store with the contents on disk via an administrative interface and/or a drush command.
Level 3: Configuration API
At this level are the actual API functions that module developers will interact with in order to manipulate configuration values; essentially, a replacement for variable_get()/variable_set().
// Load a set of configuration out of the active store.
// 'prefix.name' refers to the filename of the .yml file, without the extension.
$config = \Drupal::config('prefix.name');
// Access a single value out of the store.
// Change a value and save it back to both the active store and the filesystem.
$config->set('my.value','my new value');
Modules provide default configuration files which are copied to the site's config directory on installation.