1 config.inc config($config_file, $type = 'active')

Retrieves a configuration object.

This is the main entry point to the configuration API. Calling

config(book.admin) 

will return a configuration object in which the book module can store its administrative settings.

Parameters

string $config_file: The name of the configuration object to retrieve. The name corresponds to an JSON configuration file. For

config(book.admin) 

, the config object returned will contain the contents of book.admin.json.

string $type: (optional) The type of config directory to return. Backdrop core provides 'active' and 'staging'. Defaults to 'active'.

Return value

Config: A Config object containing the specified configuration settings.

File

core/includes/config.inc, line 26
This is the API for configuration storage.

Code

function config($config_file, $type = 'active') {
  // Use the advanced backdrop_static() pattern, since this is called very often.
  static $backdrop_static_fast;
  if (!isset($backdrop_static_fast)) {
    $backdrop_static_fast['loaded_configs'] = &backdrop_static(__FUNCTION__);
  }
  $loaded_configs = &$backdrop_static_fast['loaded_configs'];

  if (!isset($loaded_configs[$type][$config_file])) {
    $storage = config_get_config_storage($type);
    $config = new Config($config_file, $storage);
    $config->load();
    $cache = $config->get('_config_static');
    if ($cache) {
      $loaded_configs[$type][$config_file] = $config;
    }
  }
  else {
    $config = $loaded_configs[$type][$config_file];
  }

  return $config;
}