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';
if (is_dir($project_config_dir)) {
$storage = new ConfigFileStorage($project_config_dir);
$files = glob($project_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();
}
}
}
}
}