diff --git a/core/lib/Drupal/Core/Extension/ModuleHandler.php b/core/lib/Drupal/Core/Extension/ModuleHandler.php index 3461595..656e918 100644 --- a/core/lib/Drupal/Core/Extension/ModuleHandler.php +++ b/core/lib/Drupal/Core/Extension/ModuleHandler.php @@ -546,13 +546,6 @@ public function enable($module_list, $enable_dependencies = TRUE) { unset($module_list[$module]); continue; } - // Throw an exception if the module name is too long. - if (strlen($module) > DRUPAL_EXTENSION_NAME_MAX_LENGTH) { - throw new ExtensionNameLengthException(format_string('Module name %name is over the maximum allowed length of @max characters.', array( - '%name' => $module, - '@max' => DRUPAL_EXTENSION_NAME_MAX_LENGTH, - ))); - } $module_list[$module] = $module_data[$module]->sort; // Add dependencies to the list, with a placeholder weight. @@ -574,6 +567,16 @@ public function enable($module_list, $enable_dependencies = TRUE) { $module_list = array_keys($module_list); } + foreach ($module_list as $module) { + // Throw an exception if the module name is too long. + if (strlen($module) > DRUPAL_EXTENSION_NAME_MAX_LENGTH) { + throw new ExtensionNameLengthException(format_string('Module name %name is over the maximum allowed length of @max characters.', array( + '%name' => $module, + '@max' => DRUPAL_EXTENSION_NAME_MAX_LENGTH, + ))); + } + } + // Required for module installation checks. include_once DRUPAL_ROOT . '/core/includes/install.inc'; diff --git a/core/modules/system/lib/Drupal/system/Tests/Module/ModuleEnable.php b/core/modules/system/lib/Drupal/system/Tests/Module/ModuleEnable.php index 427f86f..211b867 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Module/ModuleEnable.php +++ b/core/modules/system/lib/Drupal/system/Tests/Module/ModuleEnable.php @@ -58,6 +58,15 @@ function testModuleNameLength() { catch (ExtensionNameLengthException $e) { $this->pass($message); } + + // Since for the UI, the submit callback uses FALSE, test that too. + try { + module_enable(array($module_name), FALSE); + $this->fail($message); + } + catch (ExtensionNameLengthException $e) { + $this->pass($message); + } } }