By jhodgdon on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Introduced in version:
8.x
Description:
The signature of hook_help() has changed to use route names instead of paths. The special route name help.page.[module_short_name] is used for the main module page. The current RouteMatch object is also passed in to hook_help() implementations, if more complex logic is needed.
Example - D7:
function dblog_help($path, $arg) {
switch ($path) {
case 'admin/help#dblog':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Database logging module logs system events in the Drupal database. For more information, see the online handbook entry for the <a href="@dblog">Database logging module</a>.', array('@dblog' => 'http://drupal.org/documentation/modules/dblog')) . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
...
return $output;
case 'admin/reports/dblog':
return '<p>' . t('The Database logging module monitors your website, capturing system events in a log (shown here) to be reviewed by an authorized individual at a later time. This log is a list of recorded events containing usage data, performance data, errors, warnings and operational information. It is vital to check the Recent log messages report on a regular basis, as it is often the only way to tell what is going on.') . '</p>';
}
Example, D8:
use Drupal\Core\Routing\RouteMatchInterface;
...
function dblog_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.dblog':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Database Logging module logs system events in the Drupal database. For more information, see the online handbook entry for the <a href="!dblog">Database Logging module</a>.', array('!dblog' => 'http://drupal.org/documentation/modules/dblog')) . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
...
return $output;
case 'dblog.overview':
return '<p>' . t('The Database Logging module monitors your website, capturing system events in a log (shown here) to be reviewed by an authorized individual at a later time. This log is a list of recorded events containing usage data, performance data, errors, warnings and operational information. It is vital to check the Recent log messages report on a regular basis, as it is often the only way to tell what is going on.') . '</p>';
}
}
Note: add a use for RouteMatchInterface if it is not already there.
Impacts:
Module developers
Comments
module.routing.yml
The route
help.page.YOUR_MODULEdoes not need to be added toYOUR_MODULE.routing.yml. Other help routes do need to be added to that file. For example thedblog.overviewroute is defined as:See: https://api.drupal.org/api/drupal/core%21modules%21dblog%21dblog.routing...