Drupal 7 module development and establishment module help information (hook_help)

Source: Internet
Author: User
Tags drupal

For details about how to create a module, see Drupal 7 module development and establishment.

If you want to support Chinese characters, the file format must be saved as UTF-8, no BOM

------------------------------

Hook_help provides help information for this module. We should replace the hook with our module name. Here we create a my_first_module_help file in the my_first_module.module file.

function my_first_module_help($path, $arg) {}

Parameters:

$ PathThe path of the help information to be added:

  • Write a Help file for the module, using the path:Admin/help # module_nameModule_name is your module name
  • Path: admin/People user/register
  • Path can use wildcard %, such as node/% or node/%/View

$ Arg ()Is an array corresponding to the return value of the ARG () function. It can be used when $ path contains a wildcard (%) to meet special requirements.

For example, if you use node/%/edit for $ path, When You Access Node/1/edit, $ Arg [0] = 'node ', $ Arg [1] = '1', $ Arg [2] = 'edit '.

Specific Arg () interpretation can be accessed: https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/arg/7

When you create hook_help, Arg [0] to Arg [11] have been created, but the values in these arrays are empty (empty)

Return Value:

Returns a localized string to the help document.

Example:

I want to write a help module for my first module.

<? Phpfunction my_first_module_help ($ path, $ Arg) {Switch ($ PATH) {Case "admin/help # my_first_module": $ output = '<p> '. T ("this is my first module help document "). '</P>'; return $ output; break ;}}

Note: do not end with?>

  • The druap core module automatically converts admin/help # my_first_module to admin/help/my_first_module.
  • T ("xxxxxxx") is used in $ output. When using the translation module, you can translate it into other languages without modifying the code.

Check the running result:

Log on to your Drupal website as an administrator and Click modules to go to the admin/modules page. Find my first module under the other category. After activating this module, you will find one more help link.

Click Help To Go To The Help page we created

Arg () test:

Modify code

Function my_first_module_help ($ path, $ Arg) {Switch ($ PATH) {Case "admin/help # my_first_module": $ output = '<p> '. T ("this is my first module help document "). '</P>'; return $ output; break; Case "node/%/edit": $ output = 'here is '. $ Arg [0]. ''. $ Arg [1]. ''. $ Arg [2]. 'Help information'; return $ output; break ;}}

Check the running results of Arg:

Create a page (click Add conent-> basic page to go to node/Add/page), save the page, and click Edit. Then you can see the following



Drupal 7 module development and establishment module help information (hook_help)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.