diff --git a/core/includes/config.inc b/core/includes/config.inc index fb2eca9..16586c6 100644 --- a/core/includes/config.inc +++ b/core/includes/config.inc @@ -194,7 +194,7 @@ function config_import_invoke_owner(array $config_changes, StorageInterface $sou // Check whether the module implements hook_config_import() and ask it to // handle the configuration change. $handled_by_module = FALSE; - if (module_hook($module, 'config_import')) { + if (module_hook($module, 'config_import_' . $op)) { $old_config = new Config($storage_dispatcher); $old_config ->setName($name) @@ -217,7 +217,7 @@ function config_import_invoke_owner(array $config_changes, StorageInterface $sou $new_config->setData($data); } - $handled_by_module = module_invoke($module, 'config_import', $op, $name, $new_config, $old_config); + $handled_by_module = module_invoke($module, 'config_import_' . $op, $name, $new_config, $old_config); } if (!empty($handled_by_module)) { unset($config_changes[$op][$key]); diff --git a/core/lib/Drupal/Core/Config/NullStorage.php b/core/lib/Drupal/Core/Config/NullStorage.php index 54554c9..fede4f0 100644 --- a/core/lib/Drupal/Core/Config/NullStorage.php +++ b/core/lib/Drupal/Core/Config/NullStorage.php @@ -8,7 +8,18 @@ namespace Drupal\Core\Config; /** - * Defines the Null storage controller. + * Defines a stub storage controller. + * + * This storage is always empty; the controller reads and writes nothing. + * + * The stub implementation is needed for synchronizing configuration during + * installation of a module, in which case all configuration being shipped with + * the module is known to be new. Therefore, the module installation process is + * able to short-circuit the full diff against the active store; the diff would + * yield all currently available configuration as items to remove, since they do + * not exist in the module's default configuration directory. + * + * This also can be used for testing purposes. */ class NullStorage implements StorageInterface { /** diff --git a/core/modules/config/config.api.php b/core/modules/config/config.api.php index 8cfa336..f0c3afa 100644 --- a/core/modules/config/config.api.php +++ b/core/modules/config/config.api.php @@ -13,19 +13,16 @@ */ /** - * Synchronize configuration changes. + * Create configuration upon synchronizing configuration changes. * * This callback is invoked when configuration is synchronized between storages * and allows a module to take over the synchronization of configuration data. * * Modules should implement this callback if they manage configuration data - * (such as image styles, node types, or fields), which needs to be + * (such as image styles, node types, or fields) which needs to be * prepared and passed through module API functions to properly handle a * configuration change. * - * @param string $op - * The operation to perform for the configuration data; one of 'create', - * 'delete', or 'change'. * @param string $name * The name of the configuration object. * @param Drupal\Core\Config\Config $new_config @@ -33,31 +30,78 @@ * @param Drupal\Core\Config\Config $old_config * A configuration object containing the old configuration data. */ -function MODULE_config_import($op, $name, $new_config, $old_config) { +function MODULE_config_import_create($name, $new_config, $old_config) { // Only configurable thingies require custom handling. Any other module // settings can be synchronized directly. if (strpos($name, 'config_test.dynamic.') !== 0) { return FALSE; } + $config_test = new ConfigTest($new_config); + $config_test->save(); + return TRUE; +} - if ($op == 'delete') { - // @todo image_style_delete() supports the notion of a "replacement style" - // to be used by other modules instead of the deleted style. Essential! - // But that is impossible currently, since the config system only knows - // about deleted and added changes. Introduce an 'old_ID' key within - // config objects as a standard? - $config_test = new ConfigTest($old_config); - $config_test->delete(); - } - if ($op == 'create') { - $config_test = new ConfigTest($new_config); - $config_test->save(); +/** + * Update configuration upon synchronizing configuration changes. + * + * This callback is invoked when configuration is synchronized between storages + * and allows a module to take over the synchronization of configuration data. + * + * Modules should implement this callback if they manage configuration data + * (such as image styles, node types, or fields) which needs to be + * prepared and passed through module API functions to properly handle a + * configuration change. + * + * @param string $name + * The name of the configuration object. + * @param Drupal\Core\Config\Config $new_config + * A configuration object containing the new configuration data. + * @param Drupal\Core\Config\Config $old_config + * A configuration object containing the old configuration data. + */ +function MODULE_config_import_change($name, $new_config, $old_config) { + // Only configurable thingies require custom handling. Any other module + // settings can be synchronized directly. + if (strpos($name, 'config_test.dynamic.') !== 0) { + return FALSE; } - if ($op == 'change') { - $config_test = new ConfigTest($new_config); - $config_test->setOriginal($old_config); - $config_test->save(); + $config_test = new ConfigTest($new_config); + $config_test->setOriginal($old_config); + $config_test->save(); + return TRUE; +} + +/** + * Delete configuration upon synchronizing configuration changes. + * + * This callback is invoked when configuration is synchronized between storages + * and allows a module to take over the synchronization of configuration data. + * + * Modules should implement this callback if they manage configuration data + * (such as image styles, node types, or fields) which needs to be + * prepared and passed through module API functions to properly handle a + * configuration change. + * + * @param string $name + * The name of the configuration object. + * @param Drupal\Core\Config\Config $new_config + * A configuration object containing the new configuration data. + * @param Drupal\Core\Config\Config $old_config + * A configuration object containing the old configuration data. + */ +function MODULE_config_import_delete($name, $new_config, $old_config) { + // Only configurable thingies require custom handling. Any other module + // settings can be synchronized directly. + if (strpos($name, 'config_test.dynamic.') !== 0) { + return FALSE; } + // @todo image_style_delete() supports the notion of a "replacement style" + // to be used by other modules instead of the deleted style. Essential! + // But that is impossible currently, since the config system only knows + // about deleted and added changes. Introduce an 'old_ID' key within + // config objects as a standard? + $config_test = new ConfigTest($old_config); + $config_test->delete(); return TRUE; } diff --git a/core/modules/config/tests/config_test/config_test.module b/core/modules/config/tests/config_test/config_test.module index e0a5ba5..3f3c520 100644 --- a/core/modules/config/tests/config_test/config_test.module +++ b/core/modules/config/tests/config_test/config_test.module @@ -5,9 +5,9 @@ use Drupal\config_test\ConfigTest; require_once dirname(__FILE__) . '/config_test.hooks.inc'; /** - * Implements hook_config_import(). + * Implements MODULE_config_import_create(). */ -function config_test_config_import($op, $name, $new_config, $old_config) { +function config_test_config_import_create($name, $new_config, $old_config) { // Set a global value we can check in test code. $GLOBALS['hook_config_import'] = __FUNCTION__; @@ -16,20 +16,43 @@ function config_test_config_import($op, $name, $new_config, $old_config) { if (strpos($name, 'config_test.dynamic.') !== 0) { return FALSE; } + $config_test = new ConfigTest($new_config); + $config_test->save(); + return TRUE; +} - if ($op == 'delete') { - $config_test = new ConfigTest($old_config); - $config_test->delete(); - } - if ($op == 'create') { - $config_test = new ConfigTest($new_config); - $config_test->save(); +/** + * Implements MODULE_config_import_change(). + */ +function config_test_config_import_change($name, $new_config, $old_config) { + // Set a global value we can check in test code. + $GLOBALS['hook_config_import'] = __FUNCTION__; + + // Only configurable thingies require custom handling. Any other module + // settings can be synchronized directly. + if (strpos($name, 'config_test.dynamic.') !== 0) { + return FALSE; } - if ($op == 'change') { - $config_test = new ConfigTest($new_config); - $config_test->setOriginal($old_config); - $config_test->save(); + $config_test = new ConfigTest($new_config); + $config_test->setOriginal($old_config); + $config_test->save(); + return TRUE; +} + +/** + * Implements MODULE_config_import_delete(). + */ +function config_test_config_import_delete($name, $new_config, $old_config) { + // Set a global value we can check in test code. + $GLOBALS['hook_config_import'] = __FUNCTION__; + + // Only configurable thingies require custom handling. Any other module + // settings can be synchronized directly. + if (strpos($name, 'config_test.dynamic.') !== 0) { + return FALSE; } + $config_test = new ConfigTest($old_config); + $config_test->delete(); return TRUE; } diff --git a/core/modules/image/image.module b/core/modules/image/image.module index 363ddd6..397ac95 100644 --- a/core/modules/image/image.module +++ b/core/modules/image/image.module @@ -500,32 +500,47 @@ function image_path_flush($path) { } /** - * Implements hook_config_import(). + * Implements MODULE_config_import_create(). */ -function image_config_import($op, $name, $new_config, $old_config) { +function image_config_import_create($name, $new_config, $old_config) { // Only image styles require custom handling. Any other module settings can be // synchronized directly. if (strpos($name, 'image.style.') !== 0) { return FALSE; } + $style = $new_config->get(); + return image_style_save($style); +} - if ($op == 'delete') { - // @todo image_style_delete() supports the notion of a "replacement style" - // to be used by other modules instead of the deleted style. Essential! - // But that is impossible currently, since the config system only knows - // about deleted and added changes. Introduce an 'old_ID' key within - // config objects as a standard? - $style = $old_config->get(); - return image_style_delete($style); - } - if ($op == 'create') { - $style = $new_config->get(); - return image_style_save($style); +/** + * Implements MODULE_config_import_change(). + */ +function image_config_import_change($name, $new_config, $old_config) { + // Only image styles require custom handling. Any other module settings can be + // synchronized directly. + if (strpos($name, 'image.style.') !== 0) { + return FALSE; } - if ($op == 'change') { - $style = $new_config->get(); - return image_style_save($style); + $style = $new_config->get(); + return image_style_save($style); +} + +/** + * Implements MODULE_config_import_delete(). + */ +function image_config_import_delete($name, $new_config, $old_config) { + // Only image styles require custom handling. Any other module settings can be + // synchronized directly. + if (strpos($name, 'image.style.') !== 0) { + return FALSE; } + // @todo image_style_delete() supports the notion of a "replacement style" + // to be used by other modules instead of the deleted style. Essential! + // But that is impossible currently, since the config system only knows + // about deleted and added changes. Introduce an 'old_ID' key within + // config objects as a standard? + $style = $old_config->get(); + return image_style_delete($style); } /**