diff --git a/core/lib/Drupal/Core/Extension/ModuleHandler.php b/core/lib/Drupal/Core/Extension/ModuleHandler.php index 727ab68..2cd64a7 100644 --- a/core/lib/Drupal/Core/Extension/ModuleHandler.php +++ b/core/lib/Drupal/Core/Extension/ModuleHandler.php @@ -1085,4 +1085,12 @@ public function getName($module) { $module_data = system_rebuild_module_data(); return $module_data[$module]->info['name']; } + + /** + * {@inheritdoc} + */ + public function invalidCore($core) { + return substr(\Drupal::CORE_COMPATIBILITY, 0, 1) != substr($core, 0, 1) || version_compare(\Drupal::VERSION, $core, '<'); + } + } diff --git a/core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php b/core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php index 48b5760..15b07a5 100644 --- a/core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php +++ b/core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php @@ -357,4 +357,15 @@ public function getModuleDirectories(); */ public function getName($theme); + /** + * Check a module's core compatibility + * + * @param $core + * The value of the core key in a module .info.yml file. + * + * @return bool + * TRUE if invalid or incompatible, FALSE otherwise. + */ + public function invalidCore($core); + } diff --git a/core/modules/system/src/Form/ModulesListForm.php b/core/modules/system/src/Form/ModulesListForm.php index 508e468..1540c29 100644 --- a/core/modules/system/src/Form/ModulesListForm.php +++ b/core/modules/system/src/Form/ModulesListForm.php @@ -230,20 +230,6 @@ public function buildForm(array $form, FormStateInterface $form_state) { } /** - * Check a module's core compatibility - * - * @param $core - * The value of the core key in a module .info.yml file. - * - * @return bool - * TRUE if invalid or incompatible, FALSE otherwise. - */ - protected function invalidCore($core) { - // @todo Move this method to the \Drupal class? - return substr(\Drupal::CORE_COMPATIBILITY, 0, 1) != substr($core, 0, 1) || version_compare(\Drupal::VERSION, $core, '<'); - } - - /** * Builds a table row for the system modules page. * * @param array $modules @@ -350,7 +336,7 @@ protected function buildRow(array $modules, Extension $module, $distribution) { $reasons = array(); // Check the core compatibility. - if ($this->invalidCore($module->info['core'])) { + if ($this->moduleHandler->invalidCore($module->info['core'])) { $compatible = FALSE; $reasons[] = $this->t('This version is not compatible with Drupal !core_version and should be replaced.', array( '!core_version' => \Drupal::VERSION, @@ -395,7 +381,7 @@ protected function buildRow(array $modules, Extension $module, $distribution) { } // Disable the checkbox if the dependency is incompatible with this // version of Drupal core. - elseif ($this->invalidCore($modules[$dependency]->info['core'])) { + elseif ($this->moduleHandler->invalidCore($modules[$dependency]->info['core'])) { $row['#requires'][$dependency] = $this->t('@module (incompatible with this version of Drupal core)', array( '@module' => $name, )); diff --git a/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php b/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php index bc5da97..6efc7ff 100644 --- a/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php @@ -507,4 +507,23 @@ public function testGetModuleDirectories() { $this->moduleHandler->addModule('module', 'place'); $this->assertEquals(array('module' => DRUPAL_ROOT . '/place'), $this->moduleHandler->getModuleDirectories()); } + + /** + * @covers ::invalidCore + */ + public function testInvalidCore() { + $versions = array( + // Core version => invalid. + '7.x' => TRUE, + '7.24' => TRUE, + '8.x' => FALSE, + '8.0.x' => FALSE, + '8.1.x' => TRUE, + '9.0.x' => TRUE, + ); + foreach ($versions as $version => $incompatible) { + $this->assertEquals($this->moduleHandler->invalidCore($version), $incompatible); + } + } + }