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

Validate configuration deletions before deleting them.

If any problems are encountered with the configuration, implementations of this hook should throw a ConfigValidateException to prevent the configuration from being deleted.

Parameters

Config $active_config: The configuration object for the settings about to be deleted.

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 143
Documentation for hooks provided by Config module.

Code

function hook_config_delete_validate(Config $active_config, $all_changes) {
  if (strpos($active_config->getName(), 'image.style') === 0) {
    // Check if another configuration depends on this configuration.
    if (!isset($all_changes['my_module.settings']) || $all_changes['my_module.settings'] !== 'delete') {
      $my_config = config('my_module.settings');
      $image_style_name = $active_config->get('name');
      if ($my_config->get('image_style') === $image_style_name) {
        throw new ConfigValidateException(t('The configuration "@file" cannot be deleted because the image style "@style" is in use by "@my_module".', array(
          '@file' => $active_config->getName(),
          '@style' => $image_style_name,
          '@my_module' => $my_config->getName(),
        )));
      }
    }
  }
}