1 config.api.php | hook_config_create_validate(Config $staging_config, $all_changes) |
Validate a new configuration before saving it.
If any problems are encountered with the configuration, implementations of this hook should throw a ConfigValidateException to prevent the configuration from saving.
Parameters
Config $staging_config: The configuration object for the settings about to be saved.
array|NULL $all_changes: An array of all configuration changes that are pending, keyed by the config name with the value of either "create", "update", or "delete". This may be useful if one configuration's validation depends on another. This array will be a NULL value if only a single configuration is being imported.
Throws
Related topics
File
- core/
modules/ config/ config.api.php, line 89 - Documentation for hooks provided by Config module.
Code
function hook_config_create_validate(Config $staging_config, $all_changes) {
if ($staging_config->getName() === 'my_module.settings') {
// Ensure that the name key is no longer than 64 characters.
if (strlen($staging_config->get('name')) > 64) {
throw new ConfigValidateException(t('The configuration "@file" must have a "name" attribute less than 64 characters.', array('@file' => $staging_config->getName())));
}
}
}