summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLee Rowlands2018-09-17 01:35:38 (GMT)
committerLee Rowlands2018-09-17 01:36:53 (GMT)
commite59e83e3653c6768350b7ad288d312aeb9f7e5fd (patch)
tree3d45e749065d437f6ad8c708e884cfd5c43ef1e2
parent349314ca90e472ef60a390cc9859271ee6d424c9 (diff)
Issue #2558645 by almaudoh, Vidushi Mehta, alexpott: Malformed module.info.yml prevents install with a confusing error
(cherry picked from commit 2be3c894ba23714bdf38e6f7be5203cd7179c262)
-rw-r--r--core/modules/system/src/Form/ModulesListForm.php11
-rw-r--r--core/modules/system/tests/src/Functional/Form/ModulesListFormWebTest.php25
2 files changed, 34 insertions, 2 deletions
diff --git a/core/modules/system/src/Form/ModulesListForm.php b/core/modules/system/src/Form/ModulesListForm.php
index 3c6f2a8..ef0b240 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\PreExistingConfigException;
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 @@ class ModulesListForm extends FormBase {
];
// 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 dc63e64..52e4160 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 @@ class ModulesListFormWebTest extends BrowserTestBase {
$this->assertText('simpletest');
}
+ public function testModulesListFormWithInvalidInfoFile() {
+ $broken_info_yml = <<<BROKEN
+name: Module With Broken Info file
+type: module
+BROKEN;
+ $path = \Drupal::service('site.path') . "/modules/broken";
+ mkdir($path, 0777, TRUE);
+ file_put_contents("$path/broken.info.yml", $broken_info_yml);
+
+ $this->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"]'));
+ }
+
}