1 config.module | config_config_data_validate(Config $config, $config_info) |
Implements hook_config_data_validate().
File
- core/
modules/ config/ config.module, line 186 - Allows site administrators to modify configuration.
Code
function config_config_data_validate(Config $config, $config_info) {
// This validation only applies to configs that have module-provided info.
if (empty($config_info)) {
return;
}
// First check that the provided name matches the filename.
$config_name = $config->getName();
$data = $config->get();
if (isset($config_info['name_key'])) {
// Keys may be an array or string. Ensure each key exists.
$keys = (array) $config_info['name_key'];
$config_string = '';
foreach ($keys as $name_key) {
if (empty($data[$name_key])) {
throw new ConfigValidateException(t('The configuration "@file" must have the "@key" attribute specified.', array('@file' => $config_name, '@key' => $name_key)));
}
$config_string .= '.' . $data[$name_key];
}
// Then check the file name matches the key or list of keys.
if (strpos($config_name, $config_string) === FALSE) {
if (count($keys) === 1) {
$message = t('The "@name_key" attribute has the value "@value", which does not match the file name "@file".', array('@file' => $config_name, '@name_key' => $name_key, '@value' => $data[$name_key]));
}
else {
$message = t('The attributes for @list do not match the file name "@file".', array('@file' => $config_name, '@list' => implode(', ', $keys)));
}
throw new ConfigValidateException($message);
}
}
// Check that a label key is provided (if applicable).
if (isset($config_info['label_key'])) {
$label_key = $config_info['label_key'];
if (empty($data[$label_key])) {
throw new ConfigValidateException(t('The configuration "@file" must have a "@key" attribute specified.', array('@file' => $config_name, '@key' => $label_key)));
}
}
}