Community Documentation

hook_help

5 core.php hook_help($section)
6 core.php hook_help($path, $arg)
7 help.api.php hook_help($path, $arg)
8 help.api.php hook_help($path, $arg)

Provide online user help.

By implementing hook_help(), a module can make documentation available to the user for the module as a whole, or for specific paths. Help for developers should usually be provided via function header comments in the code, or in special API example files.

For a detailed usage example, see page_example.module.

Parameters

$path: The router menu path, as defined in hook_menu(), for the help that is being requested; e.g., 'admin/people' or 'user/register'. If the router path includes a wildcard, then this will appear in $path as %, even if it is a named %autoloader wildcard in the hook_menu() implementation; for example, node pages would have $path equal to 'node/%' or 'node/%/view'. To provide a help page for a whole module with a listing on admin/help, your hook implementation should match a path with a special descriptor after a "#" sign: 'admin/help#modulename' The main module help text, displayed on the admin/help/modulename page and linked to from the admin/help page.

$arg: An array that corresponds to the return value of the arg() function, for modules that want to provide help that is specific to certain values of wildcards in $path. For example, you could provide help for the path 'user/1' by looking for the path 'user/%' and $arg[1] == '1'. This given array should always be used rather than directly invoking arg(), because your hook implementation may be called for other purposes besides building the current page's help. Note that depending on which module is invoking hook_help, $arg may contain only empty strings. Regardless, $arg[0] to $arg[11] will always be set.

Return value

A localized string containing the help text.

Related topics

▾ 51 functions implement hook_help()

aggregator_help in modules/aggregator/aggregator.module
Implements hook_help().
block_help in modules/block/block.module
Implements hook_help().
blog_help in modules/blog/blog.module
Implements hook_help().
book_help in modules/book/book.module
Implements hook_help().
color_help in modules/color/color.module
Implements hook_help().
comment_help in modules/comment/comment.module
Implements hook_help().
contact_help in modules/contact/contact.module
Implements hook_help().
contextual_help in modules/contextual/contextual.module
Implements hook_help().
dashboard_help in modules/dashboard/dashboard.module
Implements hook_help().
dblog_help in modules/dblog/dblog.module
Implements hook_help().
field_help in modules/field/field.module
Implements hook_help().
field_sql_storage_help in modules/field/modules/field_sql_storage/field_sql_storage.module
Implements hook_help().
field_ui_help in modules/field_ui/field_ui.module
Implements hook_help().
file_help in modules/file/file.module
Implements hook_help().
filter_help in modules/filter/filter.module
Implements hook_help().
forum_help in modules/forum/forum.module
Implements hook_help().
HelpTestCase::testHelp in modules/help/help.test
Logs in users, creates dblog events, and tests dblog functionality.
HelpTestCase::verifyHelp in modules/help/help.test
Verifies the logged in user has access to the various help nodes.
help_help in modules/help/help.module
Implements hook_help().
image_help in modules/image/image.module
Implement of hook_help().
list_help in modules/field/modules/list/list.module
Implements hook_help().
locale_help in modules/locale/locale.module
Implements hook_help().
menu_get_active_help in includes/menu.inc
Returns the help associated with the active menu item.
menu_help in modules/menu/menu.module
Implements hook_help().
node_help in modules/node/node.module
Implements hook_help().
NoHelpTestCase::testMainPageNoHelp in modules/help/help.test
Ensures modules not implementing help do not appear on admin/help.
number_help in modules/field/modules/number/number.module
Implements hook_help().
openid_help in modules/openid/openid.module
Implements hook_help().
options_help in modules/field/modules/options/options.module
Implements hook_help().
overlay_help in modules/overlay/overlay.module
Implements hook_help().
path_help in modules/path/path.module
Implements hook_help().
php_help in modules/php/php.module
Implements hook_help().
poll_help in modules/poll/poll.module
Implements hook_help().
profile_help in modules/profile/profile.module
Implements hook_help().
rdf_help in modules/rdf/rdf.module
Implements hook_help().
search_help in modules/search/search.module
Implements hook_help().
shortcut_help in modules/shortcut/shortcut.module
Implements hook_help().
simpletest_help in modules/simpletest/simpletest.module
Implements hook_help().
statistics_help in modules/statistics/statistics.module
Implements hook_help().
syslog_help in modules/syslog/syslog.module
Implements hook_help().
system_help in modules/system/system.module
Implements hook_help().
taxonomy_help in modules/taxonomy/taxonomy.module
Implements hook_help().
text_help in modules/field/modules/text/text.module
Implements hook_help().
theme_file_upload_help in modules/file/file.field.inc
Returns HTML for help text based on file upload validators.
toolbar_help in modules/toolbar/toolbar.module
Implements hook_help().
tracker_help in modules/tracker/tracker.module
Implements hook_help().
translation_help in modules/translation/translation.module
Implements hook_help().
trigger_help in modules/trigger/trigger.module
Implements hook_help().
update_help in modules/update/update.module
Implements hook_help().
user_help in modules/user/user.module
Implement hook_help().
xmlrpc_server_method_help in includes/xmlrpcs.inc
Returns the help for an XML-RPC method.

File

modules/help/help.api.php, line 49
Hooks provided by the Help module.

Code

<?php
function hook_help($path, $arg) {
  switch ($path) {
    // Main module help for the block module
    case 'admin/help#block':
      return '<p>' . t('Blocks are boxes of content rendered into an area, or region, of a web page. The default theme Bartik, for example, implements the regions "Sidebar first", "Sidebar second", "Featured", "Content", "Header", "Footer", etc., and a block may appear in any one of these areas. The <a href="@blocks">blocks administration page</a> provides a drag-and-drop interface for assigning a block to a region, and for controlling the order of blocks within regions.', array('@blocks' => url('admin/structure/block'))) . '</p>';

      // Help for another path in the block module
    case 'admin/structure/block':
      return '<p>' . t('This page provides a drag-and-drop interface for assigning a block to a region, and for controlling the order of blocks within regions. Since not all themes implement the same regions, or display regions in the same way, blocks are positioned on a per-theme basis. Remember that your changes will not be saved until you click the <em>Save blocks</em> button at the bottom of the page.') . '</p>';
  }
}
?>

Comments

Another example: /**  *

Another example:

/**
  * Implement hook_help()
  */
function yourmodulename_help($path, $arg) {
switch ($path) {
case 'admin/help#yourmodulename':
   $output = '';
   $output .= '<h3>' . t('About') . '</h3>';
   $output .= '<p>' . t("A helpful entry about your module") . '<p>';
return $output;
   }
}

A better example

@bhosmer - the extra $output in your example may have side effects, such as for example #yourmodulename not being defined on the admin/help page.

A cleaner way to do this without errors would to just return your output:

/**
  * Implement hook_help()
  */
function yourmodulename_help($path, $arg) {
switch ($path) {
case 'admin/help#yourmodulename':
   return '' .  '<h3>' . t('About') . '</h3>' . '<p>' . t("A helpful entry about your module") . '<p>'
   }
}

You can wrap your output in a variable if you need to, however the example you give will probably throw a warning in D7.

Caching

When experimenting with hook_help(), or adding it to an existing module, there is some caching in effect. Possibly in the menu router.
If you don't see the results you expect, try flushing your caches.

Module administration page

Drupal 7

Module administration page - on bottom of help page
Example, go to help page and click on block.
Now at the bottom you will see the block administration page.
The code for generating this is in core.
See help.admin.inc in the modules/help folder.

Remember don't modify core.

// Only print list of administration pages if the module in question has
// any such pages associated to it.
$admin_tasks = system_get_module_admin_tasks($name, $info[$name]);
if (!empty($admin_tasks)) {
$links = array();
foreach ($admin_tasks as $task) {
$links[] = l($task['title'], $task['link_path'], $task['localized_options']);
}
$output .= theme('item_list', array('items' => $links, 'title' => t('@module administration pages', array('@module' => $info[$name]['name']))));
}

Calling Our variable inside t() function inside hook_help()

<?php
/**
  * Implement hook_help()
  */
function yourmodulename_help($path, $arg) {
switch (
$path) {
case
'admin/help#yourmodulename':
      
$current_theme = variable_get('theme_default');
      
$output = '<h3>';
      
$output .= t('Help Title') . '</h3>';
      
$output .= '<p>' . t('Description: @theme', array('@theme' => $current_theme)) . '</p>';
       return
$output;
   }
}
?>

Login or register to post comments