By joegraduate on
Change record status:
Draft (View all draft change records)
Project:
Introduced in branch:
10.1.x
Introduced in version:
Issue links:
Description:
Prior to 10.1, Drupal core did not provide a method or service for determining if a piece of configuration provided by a module has been modified in the site's active configuration.
A new configuration comparator service has been added that provides a method for checking to see if a piece of configuration has been modified from its original installed value.
Before this change, code for discovering configuration changes typically looked something like this:
$modified = FALSE;
$config_name = 'user.settings';
$active = \Drupal::service('config.factory')->get($config_name);
$original_hash = $active['_core']['default_config_hash'];
unset($active['uuid']);
unset($active['_core']);
$active_hash = \Drupal\Component\Utility\Crypt::hashBase64(serialize($active));
if ($original_hash !== $active_hash) {
$modified = TRUE;
}
After this change, code should look like this:
$config_name = 'user.settings';
$modified = \Drupal::service('config.comparator')->isModified($config_name);
Impacts:
Module developers
Site templates, recipes and distribution developers