diff --git a/core/lib/Drupal/Core/Extension/ModuleHandler.php b/core/lib/Drupal/Core/Extension/ModuleHandler.php index af16b507da..3b60d528bf 100644 --- a/core/lib/Drupal/Core/Extension/ModuleHandler.php +++ b/core/lib/Drupal/Core/Extension/ModuleHandler.php @@ -756,11 +756,4 @@ public function getName($module) { } } - /** - * {@inheritdoc} - */ - public function isCoreCompatible($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 b16ed6559f..c87191a894 100644 --- a/core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php +++ b/core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php @@ -398,15 +398,4 @@ public function getModuleDirectories(); */ public function getName($module); - /** - * Check a module's core compatibility - * - * @param string $core - * The value of the core key in a module .info.yml file. - * - * @return bool - * FALSE if invalid or incompatible, TRUE otherwise. - */ - public function isCoreCompatible($core); - } diff --git a/core/modules/system/src/Controller/SystemController.php b/core/modules/system/src/Controller/SystemController.php index 4a2365d273..2da0ecac0f 100644 --- a/core/modules/system/src/Controller/SystemController.php +++ b/core/modules/system/src/Controller/SystemController.php @@ -2,6 +2,7 @@ namespace Drupal\system\Controller; +use Composer\Semver\Semver; use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Extension\ThemeHandlerInterface; @@ -223,7 +224,7 @@ public function themesPage() { if (empty($theme->status)) { // Ensure this theme is compatible with this version of core. - $theme->incompatible_core = !isset($theme->info['core']) || !$this->moduleHandler()->isCoreCompatible($theme->info['core']); + $theme->incompatible_core = !isset($theme->info['core']) || !Semver::satisfies(\Drupal::VERSION, $theme->info['core']); // Require the 'content' region to make sure the main page // content has a common place in all themes. $theme->incompatible_region = !isset($theme->info['regions']['content']); diff --git a/core/modules/system/src/Form/ModulesListForm.php b/core/modules/system/src/Form/ModulesListForm.php index bfcc68f41a..26df756cb8 100644 --- a/core/modules/system/src/Form/ModulesListForm.php +++ b/core/modules/system/src/Form/ModulesListForm.php @@ -2,6 +2,7 @@ namespace Drupal\system\Form; +use Composer\Semver\Semver; use Drupal\Component\Utility\Unicode; use Drupal\Core\Config\PreExistingConfigException; use Drupal\Core\Config\UnmetDependenciesException; @@ -20,6 +21,7 @@ use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; + /** * Provides module installation interface. * @@ -295,7 +297,7 @@ protected function buildRow(array $modules, Extension $module, $distribution) { $reasons = []; // Check the core compatibility. - if (!$this->moduleHandler->isCoreCompatible($module->info['core'])) { + if (!Semver::satisfies(\Drupal::VERSION, $module->info['core'])) { $compatible = FALSE; $reasons[] = $this->t('This version is not compatible with Drupal @core_version and should be replaced.', [ '@core_version' => \Drupal::VERSION, @@ -347,7 +349,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->moduleHandler->isCoreCompatible($modules[$dependency]->info['core'])) { + elseif (!Semver::satisfies(\Drupal::VERSION, $modules[$dependency]->info['core'])) { $row['#requires'][$dependency] = $this->t('@module (incompatible with this version of Drupal core)', [ '@module' => $name, ]); diff --git a/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php b/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php index 515e12273e..36973a8b2a 100644 --- a/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php @@ -506,42 +506,4 @@ public function testGetModuleDirectories() { $this->assertEquals(['module' => $this->root . '/place'], $module_handler->getModuleDirectories()); } - /** - * @dataProvider providerIsCoreCompatible - * @covers ::isCoreCompatible - */ - public function testIsCoreCompatible($version, $compatible) { - $this->assertEquals($compatible, $this->getModuleHandler()->isCoreCompatible($version)); - } - - /** - * Provides data for the invalid core test. - * - * @return array - * An array of versions and whether they should be valid. - */ - public function providerIsCoreCompatible() { - $current = \Drupal::VERSION; - list($major, $minor) = explode('.', $current); - - // Calculate older and newer. - $older = $major - 1; - $newer = $major + 1; - $newer_minor = $major . '.' . ($minor + 1); - - // Core version => valid. - $versions = [ - // Invalid. - ["{$older}.x", FALSE], - ["{$older}.24", FALSE], - ["{$newer_minor}.x", FALSE], - ["{$newer}.0.x", FALSE], - // Valid. - ["{$major}.x", TRUE], - ["{$major}.{$minor}.x", TRUE], - ]; - - return $versions; - } - }