diff --git a/core/lib/Drupal/Core/Extension/ModuleHandler.php b/core/lib/Drupal/Core/Extension/ModuleHandler.php index 81fe970..92e3768 100644 --- a/core/lib/Drupal/Core/Extension/ModuleHandler.php +++ b/core/lib/Drupal/Core/Extension/ModuleHandler.php @@ -810,13 +810,27 @@ public function uninstall($module_list = array(), $uninstall_dependents = TRUE) $module_list = array_keys($module_list); } + // Modules must be enabled before they are uninstalled. + $this->enable($module_list, FALSE); + $schema_store = \Drupal::keyValue('system.schema'); + $module_config = \Drupal::config('system.module'); $disabled_config = \Drupal::config('system.module.disabled'); foreach ($module_list as $module) { // Uninstall the module. module_load_install($module); $this->invoke($module, 'uninstall'); drupal_uninstall_schema($module); + $module_config + ->clear("enabled.$module") + ->save(); + + // Update the current ModuleHandler instance to remove the module, and + // also update the kernel to remove it. + $module_filenames = $this->getModuleList(); + unset($module_filenames[$module]); + $this->setModuleList($module_filenames); + drupal_container()->get('kernel')->updateModules($module_filenames, $module_filenames); // Remove all configuration belonging to the module. config_uninstall_default_config('module', $module); @@ -861,8 +875,20 @@ public function uninstall($module_list = array(), $uninstall_dependents = TRUE) drupal_get_installed_schema_version(NULL, TRUE); if (!empty($module_list)) { + // @todo Most of the following should happen in above loop already. + + // Refresh the system list to exclude the uninstalled modules. + // @todo Only needed to rebuild theme info. + // @see system_list_reset() + system_list_reset(); + + entity_info_cache_clear(); + // Let other modules react. $this->invokeAll('modules_uninstalled', array($module_list)); + + // Update the theme registry to remove the newly-uninstalled modules. + drupal_theme_rebuild(); } return TRUE; diff --git a/core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php b/core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php index b93e3e8..a2561a1 100644 --- a/core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php +++ b/core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php @@ -303,12 +303,11 @@ public function enable($module_list, $enable_dependencies = TRUE); public function disable($module_list, $disable_dependents = TRUE); /** - * Uninstalls a given list of disabled modules. + * Uninstalls a given list of modules. * * @param array $module_list - * The modules to uninstall. It is the caller's responsibility to ensure that - * all modules in this list have already been disabled before this function - * is called. + * The modules to uninstall. If any of the modules are disabled, they will + * first be enabled by this function, then uninstalled. * @param bool $uninstall_dependents * (optional) If TRUE, the function will check that all modules which depend * on the passed-in module list either are already uninstalled or contained in