1 config.inc config_install_default_config($project, $config_name = NULL)

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

@since 1.26.0 First parameter changed from $module to $project.

Parameters

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

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

File

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

Code

function config_install_default_config($project, $config_name = NULL) {
  $project_path = NULL;
  foreach (array('module', 'theme') as $project_type) {
    if ($project_path = backdrop_get_path($project_type, $project)) {
      break;
    }
  }
  $project_config_dir = $project_path . '/config';
  $storage = new ConfigFileStorage($project_config_dir);

  $default_config_names = config_get_default_config_names($project);
  foreach ($default_config_names as $default_config_name) {
    // 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.
    if (is_null($config_name) || $default_config_name === $config_name) {
      $data = $storage->read($default_config_name);
      $config = config($default_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();
      }
    }
  }
}