From 205729d91227233a09a7cc9aaab38ac6c972864a Mon Sep 17 00:00:00 2001 From: catch <catch@35733.no-reply.drupal.org> Date: Mon, 13 Dec 2021 17:09:15 +0000 Subject: [PATCH] Issue #3239287 by alexpott, longwave: Fix \Drupal\Core\Extension\ModuleDependencyMessageTrait to not cause deprecations in PHP 8.1 --- .../ModuleDependencyMessageTrait.php | 2 +- core/modules/system/system.install | 2 +- .../src/Functional/Module/DependencyTest.php | 43 +++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/core/lib/Drupal/Core/Extension/ModuleDependencyMessageTrait.php b/core/lib/Drupal/Core/Extension/ModuleDependencyMessageTrait.php index 2440e31317f6..d91085a0e68a 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 88d30e538711..f07133bcd427 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 7ec785f3f591..54e4e0d82d13 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. */ -- GitLab