protected ConfigImportSubscriber::validateModules(ConfigImporter $config_importer)
Validates module installations and uninstallations.
\Drupal\Core\Config\ConfigImporter $config_importer: The configuration importer.
protected function validateModules(ConfigImporter $config_importer) { $core_extension = $config_importer->getStorageComparer()->getSourceStorage()->read('core.extension'); // Get a list of modules with dependency weights as values. $module_data = $this->getModuleData(); $nonexistent_modules = array_keys(array_diff_key($core_extension['module'], $module_data)); foreach ($nonexistent_modules as $module) { $config_importer->logError($this->t('Unable to install the %module module since it does not exist.', array('%module' => $module))); } // Ensure that all modules being installed have their dependencies met. $installs = $config_importer->getExtensionChangelist('module', 'install'); foreach ($installs as $module) { $missing_dependencies = []; foreach (array_keys($module_data[$module]->requires) as $required_module) { if (!isset($core_extension['module'][$required_module])) { $missing_dependencies[] = $module_data[$required_module]->info['name']; } } if (!empty($missing_dependencies)) { $module_name = $module_data[$module]->info['name']; $message = $this->formatPlural(count($missing_dependencies), 'Unable to install the %module module since it requires the %required_module module.', 'Unable to install the %module module since it requires the %required_module modules.', array('%module' => $module_name, '%required_module' => implode(', ', $missing_dependencies)) ); $config_importer->logError($message); } } // Settings is safe to use because settings.php is written before any module // is installed. $install_profile = Settings::get('install_profile'); // Ensure that all modules being uninstalled are not required by modules // that will be installed after the import. $uninstalls = $config_importer->getExtensionChangelist('module', 'uninstall'); foreach ($uninstalls as $module) { foreach (array_keys($module_data[$module]->required_by) as $dependent_module) { if ($module_data[$dependent_module]->status && !in_array($dependent_module, $uninstalls, TRUE) && $dependent_module !== $install_profile) { $module_name = $module_data[$module]->info['name']; $dependent_module_name = $module_data[$dependent_module]->info['name']; $config_importer->logError($this->t('Unable to uninstall the %module module since the %dependent_module module is installed.', array('%module' => $module_name, '%dependent_module' => $dependent_module_name))); } } } // Ensure that the install profile is not being uninstalled. if (in_array($install_profile, $uninstalls)) { $profile_name = $module_data[$install_profile]->info['name']; $config_importer->logError($this->t('Unable to uninstall the %profile profile since it is the install profile.', array('%profile' => $profile_name))); } }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!EventSubscriber!ConfigImportSubscriber.php/function/ConfigImportSubscriber::validateModules/8.1.x