How to create the module help page on Drupal 8 ?
Here an exemple : Module name : mymodule
function mymodule_help($route_name, RouteMatchInterface $route_match) {
if ($route_name == 'help.page.mymodule') {
$current_url = Url::fromRoute('<current>');
if (strstr($current_url->toString(), '/admin/help/simple_analyse') === FALSE) {
// Because system_modules() executes hook_help() for each module to 'test'
// if they will return anything, but not actually display it, we want to
// return a TRUE value if this is not actually the help page.
return TRUE;
}
$output = '<dl>';
$output .= '<dt>' . ('List of the currently available tokens on this site') . '</dt>';
$token_tree = array(
'#theme' => 'token_tree',
'#token_types' => 'all',
'#click_insert' => FALSE,
'#show_restricted' => TRUE,
);
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = \Drupal::service('renderer');
$output .= '<dd>' . $renderer->render($token_tree) . '</dd>';
$output .= '</dl>';
return $output;
}
}
Comments