1.20.x config.admin.inc | config_import_single_form_validate(array &$form, array &$form_state) |
Validate handler for config_import_single_form().
File
- modules/
config/ config.admin.inc, line 419 - Admin page callbacks for the Configuration Management module.
Code
function config_import_single_form_validate(array &$form, array &$form_state) {
// Decode the submitted import.
$active_storage = config_get_config_storage('active');
try {
$data = $active_storage->decode($form_state['values']['import']);
}
catch (ConfigStorageException $e) {
$data = FALSE;
}
// Determine the matching config prefix.
$config_info = FALSE;
if ($data === FALSE) {
form_error($form['import'], t('The configuration provided could not be parsed.'));
}
elseif (empty($data['_config_name'])) {
form_error($form['import'], t('The configuration could not be imported because the "_config_name" value is missing.'));
}
else {
$config_name = $data['_config_name'];
$config_info = config_get_info($config_name);
if ($config_info === FALSE) {
form_error($form['import'], t('The configuration could not be imported because no module could recognize the "@name" configuration name.', array('@name' => $config_name)));
}
}
// Determine the type of change this is and then validate it. Deletes are
// not currently supported through the single sync form.
$config_change_type = NULL;
if ($data && $config_info) {
$active_config_exists = $active_storage->read($config_name) !== FALSE;
if ($active_config_exists) {
$config_change_type = 'update';
}
else {
$config_change_type = 'create';
}
try {
config_sync_validate_file($config_name, $config_change_type, NULL, $data);
}
catch (ConfigValidateException $e) {
form_error($form['import'], $e->getMessage());
}
}
// Store the decoded version of the submitted import.
$form_state['config_data'] = $data;
$form_state['config_change_type'] = $config_change_type;
}