Description

While in Drupal 7 most module and theme configuration is stored in the variables table in the database, in Backdrop configuration is stored in flat files, and retrieved via Configuration Management (CMI). These files are often called configuration (or config) files, and end in a .json extension. By default, active config files are saved into a BACKDROP_ROOT/files/config_xxxx/active directory (where xxxx is a long alphanumeric string, generated during install, and entered into settings.php).

A trio of handy functions were provided in Drupal 7, to manipulate these variables: variable_get(), variable_set(), and variable_del(). Backdrop provides the corresponding config_get() and config_set() functions to manage the retrieval and writing to disk (config_del() coming soon).

For the purpose of backwards compatibility with Drupal 7, both the variables database table and the variable_* functions still exist in Backdrop 1.x. They have been deprecated though, and will be removed in Backdrop 2.0; so conversion to the respective config_ functions is highly recommended.

Examples

Instead of:

$variable = variable_get('foo', 'bar');
variable_set('foo', $variable);
variable_del('foo');

Use CMI

$variable = config_get('mymodule.settings', 'foo');
config_set('mymodule.settings', 'foo', $variable);

$config = config('mymodule.settings');
$config->clear('foo');
$config->save();

The above will read and write to a JSON file called mymodule.settings.json in the active config directory.

Every time you call config_get() or config_set(), it hits the disk to read/write the file. If you're doing a lot of reads or writes, it's better to do all the reads at once and all the writes at once like this:

$config = config('mymodule.settings');
$value = $config->get('foo');

// Some code to determine new $value.

$config->set('foo', $value);
$config->set('baz', 'boo');
$config->save();

Modules will also need to declare information about config files in hook_config_info(). Further configuration documentation can be found in config.api.php

Example

/**
* Implements hook_config_info().
*/
function contact_config_info() {
  $prefixes['contact.settings'] = array(
    'label' => t('Contact settings'),
    'group' => t('Contact'),
  );
  $prefixes['contact.categories'] = array(
    'label' => t('Contact categories'),
    'group' => t('Contact'),
  );
  return $prefixes;
}
Introduced in branch: 
1.0.x
Introduced in version: 
1.0.0
Impacts: 
Module developers
Theme developers