diff --git a/core/lib/Drupal/Core/Extension/ModuleHandler.php b/core/lib/Drupal/Core/Extension/ModuleInstaller.php similarity index 40% copy from core/lib/Drupal/Core/Extension/ModuleHandler.php copy to core/lib/Drupal/Core/Extension/ModuleInstaller.php index 028d7d4..f5e3c2d 100644 --- a/core/lib/Drupal/Core/Extension/ModuleHandler.php +++ b/core/lib/Drupal/Core/Extension/ModuleInstaller.php @@ -2,690 +2,37 @@ /** * @file - * Contains Drupal\Core\Extension\ModuleHandler. + * Contains \Drupal\Core\Extension\ModuleInstaller. */ namespace Drupal\Core\Extension; -use Drupal\Component\Graph\Graph; use Drupal\Component\Serialization\Yaml; -use Drupal\Component\Utility\NestedArray; -use Drupal\Component\Utility\String; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\DrupalKernelInterface; /** - * Class that manages modules in a Drupal installation. + * Default implementation of the module installer. + * + * It registers the module in config, install its own configuration, + * installs the schema, updates the Drupal kernel and more. */ -class ModuleHandler implements ModuleHandlerInterface { +class ModuleInstaller implements ModuleInstallerInterface { [... rest of this hunk manually removed ...] @@ -771,7 +118,7 @@ public function install(array $module_list, $enable_dependencies = TRUE) { // different from the configured list of enabled modules. For all active // modules not contained in the configured enabled modules, we assume a // weight of 0. - $current_module_filenames = $this->getModuleList(); + $current_module_filenames = $this->moduleHandler->getModuleList(); $current_modules = array_fill_keys(array_keys($current_module_filenames), 0); $current_modules = module_config_sort(array_merge($current_modules, $extension_config->get('module'))); $module_filenames = array(); @@ -792,8 +139,8 @@ public function install(array $module_list, $enable_dependencies = TRUE) { // be discovered by other modules. // The current ModuleHandler instance is obsolete with the kernel // rebuild below. - $this->setModuleList($module_filenames); - $this->load($module); + $this->moduleHandler->setModuleList($module_filenames); + $this->moduleHandler->load($module); module_load_install($module); // Clear the static cache of system_rebuild_module_data() to pick up the @@ -808,7 +155,7 @@ public function install(array $module_list, $enable_dependencies = TRUE) { drupal_get_schema(NULL, TRUE); // Allow modules to react prior to the installation of a module. - $this->invokeAll('module_preinstall', array($module)); + $this->moduleHandler->invokeAll('module_preinstall', array($module)); // Now install the module's schema if necessary. drupal_install_schema($module); @@ -854,7 +201,7 @@ public function install(array $module_list, $enable_dependencies = TRUE) { // If the module has no current updates, but has some that were // previously removed, set the version to the value of // hook_update_last_removed(). - if ($last_removed = $this->invoke($module, 'update_last_removed')) { + if ($last_removed = $this->moduleHandler->invoke($module, 'update_last_removed')) { $version = max($version, $last_removed); } drupal_set_installed_schema_version($module, $version); @@ -880,7 +227,7 @@ public function install(array $module_list, $enable_dependencies = TRUE) { \Drupal::service('theme_handler')->refreshInfo(); // Allow the module to perform install tasks. - $this->invoke($module, 'install'); + $this->moduleHandler->invoke($module, 'install'); // Record the fact that it was installed. \Drupal::logger('system')->info('%module module installed.', array('%module' => $module)); @@ -889,7 +236,7 @@ public function install(array $module_list, $enable_dependencies = TRUE) { // If any modules were newly installed, invoke hook_modules_installed(). if (!empty($modules_installed)) { - $this->invokeAll('modules_installed', array($modules_installed)); + $this->moduleHandler->invokeAll('modules_installed', array($modules_installed)); } return TRUE; @@ -947,13 +294,12 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) { // configured as enabled. Custom or overridden module handlers might contain // the module already, which means that it might be loaded, but not // necessarily installed. - $schema_store = \Drupal::keyValue('system.schema'); - $entity_manager = \Drupal::entityManager(); foreach ($module_list as $module) { // Clean up all entity bundles (including fields) of every entity type // provided by the module that is being uninstalled. // @todo Clean this up in https://www.drupal.org/node/2350111. + $entity_manager = \Drupal::entityManager(); foreach ($entity_manager->getDefinitions() as $entity_type_id => $entity_type) { if ($entity_type->getProvider() == $module) { foreach (array_keys($entity_manager->getBundleInfo($entity_type_id)) as $bundle) { @@ -963,11 +309,11 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) { } // Allow modules to react prior to the uninstallation of a module. - $this->invokeAll('module_preuninstall', array($module)); + $this->moduleHandler->invokeAll('module_preuninstall', array($module)); // Uninstall the module. module_load_install($module); - $this->invoke($module, 'uninstall'); + $this->moduleHandler->invoke($module, 'uninstall'); // Remove all configuration belonging to the module. \Drupal::service('config.manager')->uninstall('module', $module); @@ -986,14 +332,15 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) { drupal_uninstall_schema($module); // Remove the module's entry from the config. + $extension_config = \Drupal::config('core.extension'); $extension_config->clear("module.$module")->save(); // Update the module handler to remove the module. // The current ModuleHandler instance is obsolete with the kernel rebuild // below. - $module_filenames = $this->getModuleList(); + $module_filenames = $this->moduleHandler->getModuleList(); unset($module_filenames[$module]); - $this->setModuleList($module_filenames); + $this->moduleHandler->setModuleList($module_filenames); // Remove any potential cache bins provided by the module. $this->removeCacheBins($module); @@ -1021,12 +368,13 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) { \Drupal::logger('system')->info('%module module uninstalled.', array('%module' => $module)); + $schema_store = \Drupal::keyValue('system.schema'); $schema_store->delete($module); } drupal_get_installed_schema_version(NULL, TRUE); // Let other modules react. - $this->invokeAll('modules_uninstalled', array($module_list)); + $this->moduleHandler->invokeAll('modules_uninstalled', array($module_list)); return TRUE; } @@ -1104,7 +433,7 @@ protected function updateKernel($module_filenames) { // After rebuilding the container we need to update the injected // dependencies. $container = $this->kernel->getContainer(); - $this->cacheBackend = $container->get('cache.bootstrap'); + $this->moduleHandler = $container->get('module_handler'); } }