diff --git a/core/includes/install.inc b/core/includes/install.inc index 7d51db6..1f52907 100644 --- a/core/includes/install.inc +++ b/core/includes/install.inc @@ -980,20 +980,26 @@ function drupal_check_module($module) { foreach ($requirements as $requirement) { if (isset($requirement['severity']) && $requirement['severity'] == REQUIREMENT_ERROR) { $message = []; + // If the requirement description is already a render array, add it to + // the message array. if (is_array($requirement['description'])) { $message['description'] = $requirement['description']; } + // Otherwise, add a #markup element for the description string. else { $message['description'] = [ '#markup' => $requirement['description'], - '#suffix' => ' ', + '#weight' => 0, ]; } + // If a required value was provided for the item, add it to the error + // message. See the hook_requirements() documentation. if (isset($requirement['value']) && $requirement['value']) { $message['version'] = [ - '#prefix' => '(', + '#prefix' => ' (', '#markup' => t('Currently using @item version @version', array('@item' => $requirement['title'], '@version' => $requirement['value'])), '#suffix' => ')', + '#weight' => 1, ]; } \Drupal::service('renderer')->renderPlain($message); diff --git a/core/modules/system/src/Tests/Module/DependencyTest.php b/core/modules/system/src/Tests/Module/DependencyTest.php index 9fed238..05f17cd 100644 --- a/core/modules/system/src/Tests/Module/DependencyTest.php +++ b/core/modules/system/src/Tests/Module/DependencyTest.php @@ -108,7 +108,7 @@ function testEnableRequirementsFailureDependency() { \Drupal::state()->set('requirements1_test.phase', 'install'); \Drupal::state()->set('requirements1_test.severity', REQUIREMENT_ERROR); - // Attempt to install both modules at the same time. + // Attempt to install both modules at the same time. $edit = array(); $edit['modules[Testing][requirements1_test][enable]'] = 'requirements1_test'; $edit['modules[Testing][requirements2_test][enable]'] = 'requirements2_test'; diff --git a/core/modules/system/src/Tests/Module/HookRequirementsTest.php b/core/modules/system/src/Tests/Module/HookRequirementsTest.php index 016c59e..4369f10 100644 --- a/core/modules/system/src/Tests/Module/HookRequirementsTest.php +++ b/core/modules/system/src/Tests/Module/HookRequirementsTest.php @@ -48,9 +48,8 @@ class HookRequirementsTest extends ModuleTestBase { * @see requirements1_test_requirements() */ function testHookRequirements() { - - // Test installing the module with all possible combinations of values - // in the hook_requirements() hook. + // Test installing the module with all possible combinations of values in + // the hook_requirements() hook. // Test all allowed severities. foreach ([REQUIREMENT_ERROR, REQUIREMENT_WARNING, REQUIREMENT_OK, REQUIREMENT_INFO] as $this->severity) { @@ -71,8 +70,8 @@ function testHookRequirements() { \Drupal::state()->set('requirements1_test.severity', REQUIREMENT_INFO); $this->container->get('module_installer')->install(['requirements1_test']); - // Test the status report with all possible combinations of values - // in the hook_requirements() hook. + // Test the status report with all possible combinations of values in the + // hook_requirements() hook. // Test all allowed severities. foreach ([REQUIREMENT_ERROR, REQUIREMENT_WARNING, REQUIREMENT_OK, REQUIREMENT_INFO] as $this->severity) { // Test all allowed phases. @@ -87,8 +86,6 @@ function testHookRequirements() { } } } - - // @todo Test update phase separately. } /** @@ -97,7 +94,6 @@ function testHookRequirements() { * @see requirements1_test_requirements() */ protected function doInstallTest() { - // Only install phase requirement errors should fail installation. if (($this->phase == 'install') && ($this->severity == REQUIREMENT_ERROR)) { $success = FALSE; @@ -138,7 +134,6 @@ protected function doInstallTest() { else { $this->assertExpectedRequirementsMessages(); } - } /** @@ -147,7 +142,6 @@ protected function doInstallTest() { * @see requirements1_test_requirements() */ protected function doRuntimeTest() { - // Configure the module's hook_requirements(). \Drupal::state()->set('requirements1_test.phase', $this->phase); \Drupal::state()->set('requirements1_test.severity', $this->severity); @@ -176,30 +170,30 @@ protected function doRuntimeTest() { protected function assertExpectedRequirementsMessages() { // @todo Currently, the 'title' is only displayed during the install phase // if the 'value' is also defined. This may not be intentional. Fix in - // https://www.drupal.org/node/FILE-ME. + // https://www.drupal.org/node/2549803. if (($this->phase == 'install') && !$this->useValue) { $this->assertNoText('Requirements 1 title'); } else { // Normally, the requirement title should always be displayed. - $this->assertText('Requirements 1 title'); + $this->assertRaw('Requirements 1 title with markup!'); } // If the requirements description was a render array, check that it was // rendered correctly. if ($this->descriptionArray) { - $this->assertText('Requirements 1 render array'); + $this->assertRaw('Requirements 1 render array with markup!'); $this->assertText('Requirements 1 first item'); $this->assertText('Requirements 1 second item'); } // Otherwise, test for the string message. else { - $this->assertText('Requirements 1 string'); + $this->assertRaw('Requirements 1 string with markup!'); } // The value should be displayed if it was set. if ($this->useValue) { - $this->assertText('Requirements 1 value text'); + $this->assertRaw('Requirements 1 value text with markup!'); } else { $this->assertNoText('Requirements 1 value text'); diff --git a/core/modules/system/tests/modules/requirements1_test/requirements1_test.install b/core/modules/system/tests/modules/requirements1_test/requirements1_test.install index c02dc80..943dcb0 100644 --- a/core/modules/system/tests/modules/requirements1_test/requirements1_test.install +++ b/core/modules/system/tests/modules/requirements1_test/requirements1_test.install @@ -4,7 +4,8 @@ * Implements hook_requirements(). * * Test modules may use four state variables to control this hook: - * - requirements1_test.phase: Whether to add the message for 'install', 'update', or 'runtime' phase. + * - requirements1_test.phase: Whether to add the message for 'install', + * 'update', or 'runtime' phase. * - requirements1_test.severity: The value for the 'severity' of the * requirement, e.g. REQUIREMENT_ERROR * - requirements1_test.description_array: Boolean indicating whether to use a @@ -25,14 +26,14 @@ function requirements1_test_requirements($phase) { // Prepare the requirement message. $requirement = []; - $requirement['title'] = 'Requirements 1 title'; + $requirement['title'] = t('Requirements 1 title with markup!'); // Use the severity level set in the test. $requirement['severity'] = \Drupal::state()->get('requirements1_test.severity'); // Add a value to the requirement if indicated in the test. if (\Drupal::state()->get('requirements1_test.use_value')) { - $requirement['value'] = 'Requirements 1 value text'; + $requirement['value'] = t('Requirements 1 value text with markup!'); } // Use a render array or a string for the description based on the value set @@ -40,15 +41,14 @@ function requirements1_test_requirements($phase) { if (\Drupal::state()->get('requirements1_test.description_array')) { $requirement['description'] = [ '#theme' => 'item_list', - '#title' => 'Requirements 1 render array', + '#title' => t('Requirements 1 render array with markup!'), '#items' => ['Requirements 1 first item', 'Requirements 1 second item'], ]; } else { - $requirement['description'] = 'Requirements 1 string.'; + $requirement['description'] = t('Requirements 1 string with markup!.'); } $requirements['requirements1_test'] = $requirement; return $requirements; - }