diff -u b/core/includes/module.inc b/core/includes/module.inc --- b/core/includes/module.inc +++ b/core/includes/module.inc @@ -1176,13 +1176,17 @@ */ function module_set_weight($module, $weight) { $config = config('system.module'); - $config_disabled = config('system.module.disabled'); + + // If the module is enabled it will be in the system.module config file. if ($config->get($module) !== NULL) { $config ->set($module, $weight) ->save('module_config_sort'); } - elseif ($config_disabled->get($module) !== NULL) { + // Before writing to the system.module.disabled file ensure that the module + // has been previously enabled. + else if (drupal_container()->get('keyvalue')->get('system.module.schema')->get($module) !== FALSE) { + $config_disabled = config('system.module.disabled'); // Only save non-zero weights to the system.module.disabled config file. if ($weight) { $config_disabled