1 config.api.php hook_config_update_validate(Config $staging_config, Config $active_config, $all_changes)

Validate configuration changes before saving them.

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.

Config $active_config: The current configuration object, whose values will be replaced.

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

ConfigValidateException

Related topics

File

core/modules/config/config.api.php, line 117
Documentation for hooks provided by Config module.

Code

function hook_config_update_validate(Config $staging_config, Config $active_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())));
    }
  }
}