diff --git a/core/modules/system/src/Form/ModulesListForm.php b/core/modules/system/src/Form/ModulesListForm.php index b12c4d2..01bbd72 100644 --- a/core/modules/system/src/Form/ModulesListForm.php +++ b/core/modules/system/src/Form/ModulesListForm.php @@ -224,6 +224,20 @@ 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 @@ -329,10 +343,10 @@ protected function buildRow(array $modules, Extension $module, $distribution) { $reasons = array(); // Check the core compatibility. - if ($module->info['core'] != \Drupal::CORE_COMPATIBILITY) { + if ($this->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::CORE_COMPATIBILITY, + '!core_version' => \Drupal::VERSION, )); } @@ -374,7 +388,7 @@ protected function buildRow(array $modules, Extension $module, $distribution) { } // Disable the checkbox if the dependency is incompatible with this // version of Drupal core. - elseif ($modules[$dependency]->info['core'] != \Drupal::CORE_COMPATIBILITY) { + elseif ($this->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/modules/system/src/Tests/Module/DependencyTest.php b/core/modules/system/src/Tests/Module/DependencyTest.php index 6ef1fb9..5b90e3d 100644 --- a/core/modules/system/src/Tests/Module/DependencyTest.php +++ b/core/modules/system/src/Tests/Module/DependencyTest.php @@ -80,6 +80,24 @@ function testIncompatibleCoreVersionDependency() { } /** + * Tests enabling modules with different core version specifications. + */ + function testCoreVersionDependency() { + $this->drupalGet('admin/modules'); + $checkbox = $this->xpath('//input[@type="checkbox" and @disabled="disabled" and @name="modules[Testing][system_incompatible_core_version_test_9x][enable]"]'); + $this->assert(count($checkbox) == 1, 'Checkbox for the 9.x module is disabled.'); + $checkbox = $this->xpath('//input[@type="checkbox" and @disabled="disabled" and @name="modules[Testing][system_compatible_core_version_test_80x][enable]"]'); + $this->assert(count($checkbox) == 0, 'Checkbox for the 8.0.x module is not disabled.'); + $checkbox = $this->xpath('//input[@type="checkbox" and @name="modules[Testing][system_compatible_core_version_test_80x][enable]"]'); + $this->assert(count($checkbox) == 1, 'Checkbox for the 8.0.x module is present.'); + // Attempt to install the module. + $edit = array(); + $edit['modules[Testing][system_compatible_core_version_test_80x][enable]'] = 'system_compatible_core_version_test_80x'; + $this->drupalPostForm('admin/modules', $edit, t('Save configuration')); + $this->assertModules(array('system_compatible_core_version_test_80x'), TRUE); + } + + /** * Tests enabling a module that depends on a module which fails hook_requirements(). */ function testEnableRequirementsFailureDependency() { diff --git a/core/modules/system/tests/modules/system_compatible_core_version_test_80x/system_compatible_core_version_test_80x.info.yml b/core/modules/system/tests/modules/system_compatible_core_version_test_80x/system_compatible_core_version_test_80x.info.yml new file mode 100644 index 0000000..eeb9970 --- /dev/null +++ b/core/modules/system/tests/modules/system_compatible_core_version_test_80x/system_compatible_core_version_test_80x.info.yml @@ -0,0 +1,6 @@ +name: 'System compatible core 8.0.x version test' +type: module +description: 'Support module for testing system dependencies.' +package: Testing +version: VERSION +core: 8.0.x diff --git a/core/modules/system/tests/modules/system_incompatible_core_version_test_9x/system_incompatible_core_version_test.info.yml b/core/modules/system/tests/modules/system_incompatible_core_version_test_9x/system_incompatible_core_version_test.info.yml new file mode 100644 index 0000000..4bc6e45 --- /dev/null +++ b/core/modules/system/tests/modules/system_incompatible_core_version_test_9x/system_incompatible_core_version_test.info.yml @@ -0,0 +1,6 @@ +name: 'System incompatible core 9.x version test' +type: module +description: 'Support module for testing system dependencies.' +package: Testing +version: 9.0.0 +core: 9.x diff --git a/core/modules/system/tests/modules/system_test/system_test.module b/core/modules/system/tests/modules/system_test/system_test.module index fc86adc..53d7cd5 100644 --- a/core/modules/system/tests/modules/system_test/system_test.module +++ b/core/modules/system/tests/modules/system_test/system_test.module @@ -64,6 +64,8 @@ function system_test_system_info_alter(&$info, Extension $file, $type) { 'system_incompatible_core_version_dependencies_test', 'system_incompatible_module_version_test', 'system_incompatible_core_version_test', + 'system_incompatible_core_version_test_9x', + 'system_compatible_core_version_test_80x', ))) { $info['hidden'] = FALSE; }