diff --git a/core/includes/config.inc b/core/includes/config.inc index c143dd4..05b7272 100644 --- a/core/includes/config.inc +++ b/core/includes/config.inc @@ -184,35 +184,50 @@ function config_import() { */ function config_import_invoke_owner(array $config_changes, StorageInterface $source_storage, StorageInterface $target_storage) { $storage_dispatcher = drupal_container()->get('config.storage.dispatcher'); - + // Collect data for all modules to be able to determine dependencies. + $files = system_rebuild_module_data(); + // Sorts modules by weight. + $sort = array(); + foreach (array_keys($modules) as $module) { + $sort[$module] = $files[$module]->sort; + } + array_multisort($sort, $modules); // Allow modules to take over configuration change operations for // higher-level configuration data. // First pass deleted, then new, and lastly changed configuration, in order to // handle dependencies correctly. + foreach (array('delete', 'create', 'change') as $op) { foreach ($config_changes[$op] as $key => $name) { - // Extract owner from configuration object name. - $module = strtok($name, '.'); - // 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_' . $op)) { - $old_config = new Config($storage_dispatcher); - $old_config - ->setName($name) - ->load(); - - $data = $source_storage->read($name); - $new_config = new Config($storage_dispatcher); - $new_config->setName($name); - if ($data !== FALSE) { - $new_config->setData($data); + $invokes[$module][$key] = $name; + } + foreach ($modules as $module) { + if (isset($invokes[$module])) { + foreach ($invokes[$module] as $key => $name) { + // Extract owner from configuration object name. + $module = strtok($name, '.'); + // 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_' . $op)) { + $old_config = new Config($storage_dispatcher); + $old_config + ->setName($name) + ->load(); + + $data = $source_storage->read($name); + $new_config = new Config($storage_dispatcher); + $new_config->setName($name); + if ($data !== FALSE) { + $new_config->setData($data); + } + + $handled_by_module = module_invoke($module, 'config_import_' . $op, $name, $new_config, $old_config); + } + if (!empty($handled_by_module)) { + unset($config_changes[$op][$key]); + } } - - $handled_by_module = module_invoke($module, 'config_import_' . $op, $name, $new_config, $old_config); - } - if (!empty($handled_by_module)) { - unset($config_changes[$op][$key]); } } }