diff --git a/core/lib/Drupal/Core/Extension/ModuleDependencyMessageTrait.php b/core/lib/Drupal/Core/Extension/ModuleDependencyMessageTrait.php index 2440e31317f6fe1c2e60f0c9a2837082886e5c7b..d91085a0e68a964474371d3ecc663eb99f760aa5 100644 --- a/core/lib/Drupal/Core/Extension/ModuleDependencyMessageTrait.php +++ b/core/lib/Drupal/Core/Extension/ModuleDependencyMessageTrait.php @@ -39,7 +39,7 @@ public function checkDependencyMessage(array $modules, $dependency, Dependency $ } // Check if the module is incompatible with the dependency constraints. - $version = str_replace(\Drupal::CORE_COMPATIBILITY . '-', '', $modules[$dependency]->info['version']); + $version = str_replace(\Drupal::CORE_COMPATIBILITY . '-', '', $modules[$dependency]->info['version'] ?? ''); if (!$dependency_object->isCompatible($version)) { $constraint_string = $dependency_object->getConstraintString(); return $this->t('@module_name (<span class="admin-missing">incompatible with</span> version @version)', [ diff --git a/core/modules/system/system.install b/core/modules/system/system.install index 88d30e538711170c8b5132026eae1b4046643b8f..f07133bcd4277f1fb1537265efbae8cb2f829671 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -953,7 +953,7 @@ function system_requirements($phase) { // Check for an incompatible version. $required_file = $files[$required_module]; $required_name = $required_file->info['name']; - $version = str_replace(\Drupal::CORE_COMPATIBILITY . '-', '', $required_file->info['version']); + $version = str_replace(\Drupal::CORE_COMPATIBILITY . '-', '', $required_file->info['version'] ?? ''); if (!$requirement->isCompatible($version)) { $requirements["$extension_name-$required_module"] = [ 'title' => t('Unresolved dependency'), diff --git a/core/modules/system/tests/src/Functional/Module/DependencyTest.php b/core/modules/system/tests/src/Functional/Module/DependencyTest.php index 7ec785f3f5919e688d1931ae4e8672497d1def4b..54e4e0d82d131912aa0656f90f0265d12d0fc34d 100644 --- a/core/modules/system/tests/src/Functional/Module/DependencyTest.php +++ b/core/modules/system/tests/src/Functional/Module/DependencyTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\system\Functional\Module; +use Drupal\Component\Serialization\Yaml; use Drupal\Component\Utility\Unicode; /** @@ -96,6 +97,48 @@ public function testIncompatibleCoreVersionDependency() { $this->assertSession()->fieldDisabled('modules[system_incompatible_core_version_dependencies_test][enable]'); } + /** + * Tests visiting admin/modules when a module outside of core has no version. + */ + public function testNoVersionInfo() { + // Create a module for testing. We set core_version_requirement to '*' for + // the test so that it does not need to be updated between major versions. + $info = [ + 'type' => 'module', + 'core_version_requirement' => '*', + 'name' => 'System no module version dependency test', + ]; + $path = $this->siteDirectory . '/modules/system_no_module_version_dependency_test'; + mkdir($path, 0777, TRUE); + file_put_contents("$path/system_no_module_version_dependency_test.info.yml", Yaml::encode($info)); + + $info = [ + 'type' => 'module', + 'core_version_requirement' => '*', + 'name' => 'System no module version test', + 'dependencies' => ['system_no_module_version_dependency_test'], + ]; + $path = $this->siteDirectory . '/modules/system_no_module_version_test'; + mkdir($path, 0777, TRUE); + file_put_contents("$path/system_no_module_version_test.info.yml", Yaml::encode($info)); + + $this->drupalGet('admin/modules'); + $this->assertSession()->pageTextContains('System no module version dependency test'); + $this->assertSession()->pageTextContains('System no module version test'); + + // Ensure the modules can actually be installed. + $edit['modules[system_no_module_version_test][enable]'] = 'system_no_module_version_test'; + $edit['modules[system_no_module_version_dependency_test][enable]'] = 'system_no_module_version_dependency_test'; + $this->drupalGet('admin/modules'); + $this->submitForm($edit, 'Install'); + $this->assertSession()->pageTextContains('2 modules have been enabled: System no module version dependency test, System no module version test.'); + + // Ensure status report is working. + $this->drupalLogin($this->createUser(['administer site configuration'])); + $this->drupalGet('admin/reports/status'); + $this->assertSession()->statusCodeEquals(200); + } + /** * Tests failing PHP version requirements. */