Issue #2707261 by alexpott, jhodgdon: Calling moduleInvokeAll in Help block is wrong

8.2.x
Nathaniel Catchpole 2016-04-28 21:46:32 +01:00
parent 942c1cff1b
commit 1003490b99
7 changed files with 65 additions and 8 deletions

View File

@ -88,14 +88,19 @@ class HelpBlock extends BlockBase implements ContainerFactoryPluginInterface {
return []; return [];
} }
$help = $this->moduleHandler->invokeAll('help', array($this->routeMatch->getRouteName(), $this->routeMatch)); $implementations = $this->moduleHandler->getImplementations('help');
$build = []; $build = [];
$args = [
// Remove any empty strings from $help. $this->routeMatch->getRouteName(),
foreach (array_filter($help) as $item) { $this->routeMatch,
];
foreach ($implementations as $module) {
// Don't add empty strings to $build array.
if ($help = $this->moduleHandler->invoke($module, 'help', $args)) {
// Convert strings to #markup render arrays so that they will XSS admin // Convert strings to #markup render arrays so that they will XSS admin
// filtered. // filtered.
$build[] = is_array($item) ? $item : ['#markup' => $item]; $build[] = is_array($help) ? $help : ['#markup' => $help];
}
} }
return $build; return $build;
} }

View File

@ -14,7 +14,7 @@ class HelpBlockTest extends WebTestBase {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static $modules = ['help', 'help_page_test', 'block']; public static $modules = ['help', 'help_page_test', 'block', 'more_help_page_test'];
/** /**
* The help block instance. * The help block instance.
@ -39,6 +39,12 @@ class HelpBlockTest extends WebTestBase {
$this->drupalGet('help_page_test/no_help'); $this->drupalGet('help_page_test/no_help');
// The help block should not appear when there is no help. // The help block should not appear when there is no help.
$this->assertNoText($this->helpBlock->label()); $this->assertNoText($this->helpBlock->label());
// Ensure that if two hook_help() implementations both return a render array
// the output is as expected.
$this->drupalGet('help_page_test/test_array');
$this->assertText('Help text from more_help_page_test_help module.');
$this->assertText('Help text from help_page_test_help module.');
} }
} }

View File

@ -19,6 +19,8 @@ function help_page_test_help($route_name, RouteMatchInterface $route_match) {
return t('Read the <a href=":url">online documentation for the Help Page Test module</a>.', [':url' => 'http://www.example.com']); return t('Read the <a href=":url">online documentation for the Help Page Test module</a>.', [':url' => 'http://www.example.com']);
case 'help_page_test.has_help': case 'help_page_test.has_help':
return t('I have help!'); return t('I have help!');
case 'help_page_test.test_array':
return ['#markup' => 'Help text from help_page_test_help module.'];
} }
// Ensure that hook_help() can return an empty string and not cause the block // Ensure that hook_help() can return an empty string and not cause the block

View File

@ -11,3 +11,10 @@ help_page_test.no_help:
_controller: '\Drupal\help_page_test\HelpPageTestController::noHelp' _controller: '\Drupal\help_page_test\HelpPageTestController::noHelp'
requirements: requirements:
_access: 'TRUE' _access: 'TRUE'
help_page_test.test_array:
path: '/help_page_test/test_array'
defaults:
_controller: '\Drupal\help_page_test\HelpPageTestController::testArray'
requirements:
_access: 'TRUE'

View File

@ -27,4 +27,14 @@ class HelpPageTestController {
return ['#markup' => 'A route without help.']; return ['#markup' => 'A route without help.'];
} }
/**
* Provides a route which has multiple array returns from hook_help().
*
* @return array
* A render array.
*/
public function testArray() {
return ['#markup' => 'A route which has multiple array returns from hook_help().'];
}
} }

View File

@ -0,0 +1,7 @@
name: 'More Help Page Test'
type: module
description: 'Module to test the help page.'
package: Testing
version: VERSION
core: 8.x
hidden: true

View File

@ -0,0 +1,20 @@
<?php
/**
* @file
* More Help Page Test module to test the help blocks.
*/
use \Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function more_help_page_test_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Return help for the same route as the help_page_test module.
case 'help_page_test.test_array':
return ['#markup' => 'Help text from more_help_page_test_help module.'];
}
}