Hooks

  1. drupal
    1. 4.6 includes/module.inc
    2. 4.7 includes/module.inc
    3. 5 includes/module.inc
    4. 6 includes/module.inc
    5. 7 includes/module.inc
    6. 8 core/includes/module.inc

Allow modules to interact with the Drupal core.

Drupal's module system is based on the concept of "hooks". A hook is a PHP function that is named foo_bar(), where "foo" is the name of the module (whose filename is thus foo.module) and "bar" is the name of the hook. Each hook has a defined set of parameters and a specified result type.

To extend Drupal, a module need simply implement a hook. When Drupal wishes to allow intervention from modules, it determines which modules implement a hook and call that hook in all enabled modules that implement it.

The available hooks to implement are explained here in the Hooks section of the developer documentation. The string "hook" is used as a placeholder for the module name is the hook definitions. For example, if the module file is called example.module, then hook_help() as implemented by that module would be defined as example_help().

Functions & methods

NameDescription
hook_accessDefine access restrictions.
hook_authVerify authentication of a user.
hook_blockDeclare a block or set of blocks.
hook_commentAct on comments.
hook_cronPerform periodic actions.
hook_db_rewrite_sqlAdd JOIN and WHERE statements to queries and decide whether the primary_field shall be made DISTINCT. For node objects, primary field is always called nid. For taxonomy terms, it is tid and for vocabularies it is vid. For comments, it is cid. Primary…
hook_deleteRespond to node deletion.
hook_elementsAllows modules to declare their own form element types and specify their default values.
hook_exitPerform cleanup tasks.
hook_file_downloadAllow file downloads.
hook_filterDefine content filters.
hook_filter_tipsProvide tips for using filters.
hook_footerInsert closing HTML.
hook_formDisplay a node editing form.
hook_form_alterPerform alterations before a form is rendered. One popular use of this hook is to add form elements to the node form.
hook_helpProvide online user help.
hook_infoDeclare authentication scheme information.
hook_initPerform setup tasks.
hook_insertRespond to node insertion.
hook_installInstall the current version of the database schema.
hook_linkDefine internal Drupal links.
hook_loadLoad node-type-specific information.
hook_menuDefine menu items and page callbacks.
hook_nodeapiAct on nodes defined by other modules.
hook_node_grantsGrant access to nodes.
hook_node_infoDefine the human-readable name of a node type.
hook_permDefine user permissions.
hook_pingPing another server.
hook_prepareThis is a hook used by node modules. It is called after load but before the node is shown on the add/edit form.
hook_searchDefine a custom search routine.
hook_search_preprocessPreprocess text for the search index.
hook_settingsDeclare administrative settings for a module.
hook_submitThis is a hook used by node modules. It is called after validation has succeeded and before insert/update. It is used to for actions which must happen only if the node is to be saved. Usually, $node is changed in some way and then the actual saving of…
hook_taxonomyAct on taxonomy changes.
hook_updateRespond to node updating.
hook_update_indexUpdate Drupal's full-text index for this module.
hook_update_NPerform a single update. For each patch which requires a database change add a new hook_update_N() which will be called by update.php.
hook_userAct on user account actions.
hook_validateVerify a node editing form.
hook_viewDisplay a node.
hook_xmlrpcRegister XML-RPC callbacks.
module_hookDetermine whether a module implements a hook.
module_implementsDetermine which modules are implementing a hook.
module_invokeInvoke a hook in a particular module.
module_invoke_allInvoke a hook in all enabled modules that implement it.

File

includes/module.inc, line 95
API for loading and interacting with Drupal modules.

Login or register to post comments