1.20.x config.inc config_install_default_config($module, $config_name = NULL)

Moves the default config supplied by a module to the live config directory.

Parameters

string $module: The name of the module we are installing.

string|NULL $config_name: (optional) If wanting to copy just a single configuration file from the module, specify the configuration file name without the extension.

File

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

Code

function config_install_default_config($module, $config_name = NULL) {
  $module_config_dir = backdrop_get_path('module', $module) . '/config';
  if (is_dir($module_config_dir)) {
    $storage = new ConfigFileStorage($module_config_dir);
    $files = glob($module_config_dir . '/*.json');
    foreach ($files as $file) {
      // Load config data into the active store and write it out to the
      // file system in the Backdrop config directory. Note the config name
      // needs to be the same as the file name WITHOUT the extension.
      $parts = explode('/', $file);
      $file = array_pop($parts);
      $file_config_name = str_replace('.json', '', $file);
      if (is_null($config_name) || $file_config_name === $config_name) {
        $data = $storage->read($file_config_name);
        $config = config($file_config_name);
        // We only create new configs, and do not overwrite existing ones.
        if ($config->isNew()) {
          $config->setData($data);
          module_invoke_all('config_create', $config);
          $config->save();
        }
      }
    }
  }
}