1 config.sync.inc config_sync_file($config_file, $config_change_type, $config_contents = NULL)

Save an individual configuration.

Calls all the necessary hooks to allow modules to modify any configuration changes before they are saved.

Parameters

string $config_file: The name of the config file being synced.

string $config_change_type: The type of change occurring to this config file. Must be one of the following values: "create", "update", or "delete".

string $config_contents: The configuration file's contents.

See also

hook_config_create().

hook_config_update().

hook_config_delete().

File

core/modules/config/config.sync.inc, line 202

Code

function config_sync_file($config_file, $config_change_type, $config_contents = NULL) {
  $active_config = config($config_file, 'active');

  // Read the config data from staging if contents are not provided.
  if (is_null($config_contents)) {
    $staging_config = config($config_file, 'staging')->load();
  }
  // If contents are provided, create a staging config object. This object is
  // not actually written to disk, so it should not affect any existing staged
  // configuration files when performing a single import.
  else {
    $staging_config = config($config_file, 'staging')->setData($config_contents);
  }

  switch ($config_change_type) {
    case 'create':
      $active_config->setData($staging_config->get());
      module_invoke_all('config_create', $active_config);
      $active_config->save();
      break;
    case 'update':
      $active_config->load();
      module_invoke_all('config_update', $staging_config, $active_config);
      $active_config->setData($staging_config->get())->save();
      break;
    case 'delete':
      $active_config->load();
      module_invoke_all('config_delete', $active_config);
      $active_config->delete();
      break;
  }
}