1 config.sync.inc | config_sync_validate_file($config_name, $config_change_type, $all_changes = NULL, $config_data = NULL) |
Validate an individual configuration to ensure it's safe to import.
Calls all the necessary hooks to allow modules to validate a set of configuration changes. If any module encounters a validation problem, it should throw a ConfigValidateException exception.
Parameters
string $config_name: 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".
array|NULL $all_changes: If this file is being changed with a group of other configuration files, pass in the complete set of files that are anticipated to be changed during the sync. If doing a typical sync between staging and live directories, this value can be retrieved from config_get_statuses(). If syncing a single configuration file, this value should be NULL.
array $data: The configuration data to be validated if the data is coming from a source other than the staging configuration storage.
Throws
See also
hook_config_create_validate().
hook_config_update_validate().
hook_config_delete_validate().
File
- core/
modules/ config/ config.sync.inc, line 140
Code
function config_sync_validate_file($config_name, $config_change_type, $all_changes = NULL, $config_data = NULL) {
// Read the config data from staging if contents are not provided.
if (is_null($config_data)) {
$staging_config = config($config_name, '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_name, 'staging')->setData($config_data);
}
// First check that a module claims this config file. Unclaimed configs cannot
// be managed at all, because hooks may need to be fired when performing any
// kind of change (e.g. a deleted config might need to remove database
// tables).
$config_info = config_get_info($config_name);
if (empty($config_info)) {
if ($config_change_type === 'delete') {
$message = t('The configuration "@name" is not owned by any enabled module, so it cannot be deleted. If you have disabled this module, either <a href="!enable">enable the module</a> and try the import again, or <a href="!uninstall">uninstall the module entirely</a> to clean up left-over configuration.', array('@name' => $config_name, '!enable' => url('admin/modules'), '!uninstall' => url('admin/modules/uninstall')));
}
else {
$message = t('The configuration "@name" is not owned by any module. Try enabling the module that provides this configuration, then importing again.', array('@name' => $config_name));
}
throw new ConfigValidateException($message);
}
switch ($config_change_type) {
case 'create':
$staging_config->validateData();
module_invoke_all('config_create_validate', $staging_config, $all_changes);
break;
case 'update':
$staging_config->validateData();
$active_config = config($config_name, 'active')->load();
module_invoke_all('config_update_validate', $staging_config, $active_config, $all_changes);
break;
case 'delete':
$active_config = config($config_name, 'active')->load();
module_invoke_all('config_delete_validate', $active_config, $all_changes);
break;
}
}