The configuration management system in Drupal 8 utilizes the configuration schema to describe configurations that can exist. Why is this important? It allows Drupal to properly implement typed data on stored configuration values and validate them, providing a standardized way of handling configurations for translation and configuration items.
When a module uses the configuration system to store data, it needs to provide a schema for each configuration definition it wishes to store. The schema definition is used to validate and provide typed data definitions for its values.
The following code defines the configuration schema for the navbar_awesome module, which holds two different Boolean configuration values:
navbar_awesome.toolbar:
type: config_object
label: 'Navbar Awesome toolbar settings'
mapping:
cdn:
type: boolean
label: 'Use the FontAwesome CDN library'
roboto:
type: boolean
label: 'Include Roboto from Google Fonts CDN'
This defines the navbar_awesome.toolbar configuration namespace; it belongs to the navbar_awesome module and has the toolbar configuration. We will then need two cdn and roboto subvalues that represent typed data values. A configuration YAML for this schema will be named navbar_awesome.toolbar.yml after the namespace, and it contains the following code:
cdn: true roboto: true
In turn, this is what the values will look like when represented as a PHP array:
[
'navbar_awesome' => [
'cdn' => TRUE,
'roboto' => TRUE,
]
]
The configuration factory classes then provide an object-based wrapper around these configuration definitions and provide validation of their values against the schema. For instance, if you try to save the cdn value as a string, a validation exception will be thrown.