Commit c7af20e4 authored by catch's avatar catch
Browse files

Issue #2665672 by jhodgdon: hook_help() should allow render arrays for return values

parent c7b117b2
......@@ -40,8 +40,9 @@
* The current route match. This can be used to generate different help
* output for different pages that share the same route.
*
* @return string
* A localized string containing the help text.
* @return string|array
* A render array, localized string, or object that can be rendered into
* a string, containing the help text.
*/
function hook_help($route_name, \Drupal\Core\Routing\RouteMatchInterface $route_match) {
switch ($route_name) {
......
......@@ -26,7 +26,7 @@ function help_help($route_name, RouteMatchInterface $route_match) {
}
$output .= '</ol>';
$output .= '<p>' . t('For more information, refer to the subjects listed in the Help Topics section or to the <a href=":docs">online documentation</a> and <a href=":support">support</a> pages at <a href=":drupal">drupal.org</a>.', array(':docs' => 'https://www.drupal.org/documentation', ':support' => 'https://www.drupal.org/support', ':drupal' => 'https://www.drupal.org')) . '</p>';
return $output;
return ['#markup' => $output];
case 'help.page.help':
$output = '';
......@@ -39,7 +39,7 @@ function help_help($route_name, RouteMatchInterface $route_match) {
$output .= '<dt>' . t('Providing page-specific help') . '</dt>';
$output .= '<dd>' . t('Page-specific help text provided by modules is displayed in the Help block. This block can be placed and configured on the <a href=":blocks">Block layout page</a>.', array(':blocks' => (\Drupal::moduleHandler()->moduleExists('block')) ? \Drupal::url('block.admin_display') : '#')) . '</dd>';
$output .= '</dl>';
return $output;
return ['#markup' => $output];
}
}
......
......@@ -123,10 +123,13 @@ public function helpPage($name) {
$temp = $this->moduleHandler()->invoke($name, 'help', array("help.page.$name", $this->routeMatch));
if (empty($temp)) {
$build['top']['#markup'] = $this->t('No help is available for module %module.', array('%module' => $module_name));
$build['top'] = ['#markup' => $this->t('No help is available for module %module.', array('%module' => $module_name))];
}
else {
$build['top']['#markup'] = $temp;
if (!is_array($temp)) {
$temp = ['#markup' => $temp];
}
$build['top'] = $temp;
}
// Only print list of administration pages if the module in question has
......
......@@ -90,8 +90,8 @@ public static function create(ContainerInterface $container, array $configuratio
* @param \Symfony\Component\HttpFoundation\Request $request
* The current request.
*
* @return string
* Help text of the matched route item as HTML.
* @return array|string
* Render array or string containing the help of the matched route item.
*/
protected function getActiveHelp(Request $request) {
// Do not show on a 403 or 404 page.
......@@ -100,7 +100,15 @@ protected function getActiveHelp(Request $request) {
}
$help = $this->moduleHandler->invokeAll('help', array($this->routeMatch->getRouteName(), $this->routeMatch));
return $help ? implode("\n", $help) : '';
$build = [];
foreach ($help as $item) {
if (!is_array($item)) {
$item = ['#markup' => $item];
}
$build[] = $item;
}
return $build;
}
/**
......@@ -111,10 +119,11 @@ public function build() {
if (!$help) {
return [];
}
elseif (!is_array($help)) {
return ['#markup' => $help];
}
else {
return [
'#children' => $help,
];
return $help;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment