diff --git a/core/modules/system/src/Form/ModulesListForm.php b/core/modules/system/src/Form/ModulesListForm.php index 3c6f2a8991451fb028b7dc5dc5234076ab9505d0..ef0b240ecffc593f246b486cb41fa578af50ff19 100644 --- a/core/modules/system/src/Form/ModulesListForm.php +++ b/core/modules/system/src/Form/ModulesListForm.php @@ -7,6 +7,7 @@ use Drupal\Core\Config\UnmetDependenciesException; use Drupal\Core\Access\AccessManagerInterface; use Drupal\Core\Extension\Extension; +use Drupal\Core\Extension\InfoParserException; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Extension\ModuleInstallerInterface; use Drupal\Core\Form\FormBase; @@ -143,8 +144,14 @@ public function buildForm(array $form, FormStateInterface $form_state) { ]; // Sort all modules by their names. - $modules = system_rebuild_module_data(); - uasort($modules, 'system_sort_modules_by_info_name'); + try { + $modules = system_rebuild_module_data(); + uasort($modules, 'system_sort_modules_by_info_name'); + } + catch (InfoParserException $e) { + $this->messenger()->addError($this->t('Modules could not be listed due to an error: %error', ['%error' => $e->getMessage()])); + $modules = []; + } // Iterate over each of the modules. $form['modules']['#tree'] = TRUE; diff --git a/core/modules/system/tests/src/Functional/Form/ModulesListFormWebTest.php b/core/modules/system/tests/src/Functional/Form/ModulesListFormWebTest.php index dc63e64d72d8cf623d6202d26f828082dca1c7a6..52e4160cda9084f6d289c54ee9feda7d5c00b0b0 100644 --- a/core/modules/system/tests/src/Functional/Form/ModulesListFormWebTest.php +++ b/core/modules/system/tests/src/Functional/Form/ModulesListFormWebTest.php @@ -51,4 +51,29 @@ public function testModuleListForm() { $this->assertText('simpletest'); } + public function testModulesListFormWithInvalidInfoFile() { + $broken_info_yml = <<drupalLogin( + $this->drupalCreateUser( + ['administer modules', 'administer permissions'] + ) + ); + $this->drupalGet('admin/modules'); + $this->assertSession()->statusCodeEquals(200); + + // Confirm that the error message is shown. + $this->assertSession() + ->pageTextContains('Modules could not be listed due to an error: Missing required keys (core) in ' . $path . '/broken.info.yml'); + + // Check that the module filter text box is available. + $this->assertTrue($this->xpath('//input[@name="text"]')); + } + }