Hooks

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

NameLocationDescription
custom_url_rewrite_inbounddeveloper/hooks/core.phpcustom_url_rewrite_inbound is not a hook, it's a function you can add to settings.php to alter incoming requests so they map to a Drupal path. This function is called before modules are loaded and the menu system is initialized and it changes...
custom_url_rewrite_outbounddeveloper/hooks/core.phpcustom_url_rewrite_outbound is not a hook, it's a function you can add to settings.php to alter all links generated by Drupal. This function is called from url(). This function is called very frequently (100+ times per page) so performance...
hook_accessdeveloper/hooks/node.phpDefine access restrictions.
hook_actions_deletedeveloper/hooks/core.phpExecute code after an action is deleted.
hook_action_infodeveloper/hooks/core.phpDeclare information about one or more Drupal actions.
hook_action_info_alterdeveloper/hooks/core.phpAlter the actions declared by another module.
hook_blockdeveloper/hooks/core.phpDeclare a block or set of blocks.
hook_bootdeveloper/hooks/core.phpPerform setup tasks. See also, hook_init.
hook_commentdeveloper/hooks/core.phpAct on comments.
hook_crondeveloper/hooks/core.phpPerform periodic actions.
hook_db_rewrite_sqldeveloper/hooks/core.phpRewrite database queries, usually for access control.
hook_deletedeveloper/hooks/node.phpRespond to node deletion.
hook_disabledeveloper/hooks/install.phpPerform necessary actions before module is disabled.
hook_elementsdeveloper/hooks/core.phpAllows modules to declare their own Forms API element types and specify their default values.
hook_enabledeveloper/hooks/install.phpPerform necessary actions after module is enabled.
hook_exitdeveloper/hooks/core.phpPerform cleanup tasks.
hook_file_downloaddeveloper/hooks/core.phpControl access to private file downloads and specify HTTP headers.
hook_filterdeveloper/hooks/core.phpDefine content filters.
hook_filter_tipsdeveloper/hooks/core.phpProvide tips for using filters.
hook_flush_cachesdeveloper/hooks/core.phpAdd a list of cache tables to be cleared.
hook_footerdeveloper/hooks/core.phpInsert closing HTML.
hook_formdeveloper/hooks/node.phpDisplay a node editing form.
hook_formsdeveloper/hooks/core.phpMap form_ids to builder functions.
hook_form_alterdeveloper/hooks/core.phpPerform alterations before a form is rendered.
hook_form_FORM_ID_alterdeveloper/hooks/core.phpProvide a form-specific alteration instead of the global hook_form_alter().
hook_helpdeveloper/hooks/core.phpProvide online user help.
hook_hook_infodeveloper/hooks/core.phpExpose a list of triggers (events) that your module is allowing users to assign actions to.
hook_initdeveloper/hooks/core.phpPerform setup tasks. See also, hook_boot.
hook_insertdeveloper/hooks/node.phpRespond to node insertion.
hook_installdeveloper/hooks/install.phpInstall the current version of the database schema, and any other setup tasks.
hook_linkdeveloper/hooks/core.phpDefine internal Drupal links.
hook_link_alterdeveloper/hooks/core.phpPerform alterations before links on a node are rendered. One popular use of this hook is to modify/remove links from other modules. If you want to add a link to the links section of a node, use hook_link instead.
hook_loaddeveloper/hooks/node.phpLoad node-type-specific information.
hook_localedeveloper/hooks/core.phpAllows modules to define their own text groups that can be translated.
hook_maildeveloper/hooks/core.phpPrepare a message based on parameters; called from drupal_mail().
hook_mail_alterdeveloper/hooks/core.phpAlter any aspect of email sent by Drupal. You can use this hook to add a common site footer to all outgoing email, add extra header fields, and/or modify the email in any way. HTML-izing the outgoing email is one possibility. See also drupal_mail().
hook_menudeveloper/hooks/core.phpDefine menu items and page callbacks.
hook_menu_alterdeveloper/hooks/core.phpAlter the data being saved to the {menu_router} table after hook_menu is invoked.
hook_menu_link_alterdeveloper/hooks/core.phpAlter the data being saved to the {menu_links} table by menu_link_save().
hook_nodeapideveloper/hooks/core.phpAct on nodes defined by other modules.
hook_node_access_recordsdeveloper/hooks/core.phpSet permissions for a node to be written to the database.
hook_node_grantsdeveloper/hooks/core.phpInform the node access system what permissions the user has.
hook_node_infodeveloper/hooks/node.phpDefine module-provided node types.
hook_node_operationsdeveloper/hooks/core.phpAdd mass node operations.
hook_node_typedeveloper/hooks/node.phpAct on node type changes.
hook_permdeveloper/hooks/core.phpDefine user permissions.
hook_pingdeveloper/hooks/core.phpPing another server.
hook_preparedeveloper/hooks/node.phpThis is a hook used by node modules. It is called after load but before the node is shown on the add/edit form.
hook_profile_alterdeveloper/hooks/core.phpPerform alterations profile items before they are rendered. You may omit/add/re-sort/re-categorize, etc.
hook_requirementsdeveloper/hooks/install.phpCheck installation requirements and do status reporting.
hook_schemadeveloper/hooks/install.phpDefine the current version of the database schema.
hook_schema_alterdeveloper/hooks/core.phpPerform alterations to existing database schemas.
hook_searchdeveloper/hooks/core.phpDefine a custom search routine.
hook_search_preprocessdeveloper/hooks/core.phpPreprocess text for the search index.
hook_system_info_alterdeveloper/hooks/core.phpAlter the information parsed from module and theme .info files
hook_taxonomydeveloper/hooks/core.phpAct on taxonomy changes.
hook_term_pathdeveloper/hooks/core.phpAllows modules to provide an alternative path for the terms it manages.
hook_themedeveloper/hooks/core.phpRegister a module (or theme's) theme implementations.
hook_theme_registry_alterdeveloper/hooks/core.phpAlter the theme registry information returned from hook_theme().
hook_translated_menu_link_alterdeveloper/hooks/core.phpAlter a menu link after it's translated, but before it's rendered.
hook_translation_link_alterdeveloper/hooks/core.phpPerform alterations on translation links.
hook_uninstalldeveloper/hooks/install.phpRemove any tables or variables that the module sets.
hook_updatedeveloper/hooks/node.phpRespond to node updating.
hook_update_indexdeveloper/hooks/core.phpUpdate Drupal's full-text index for this module.
hook_update_last_removeddeveloper/hooks/install.phpReturn a number which is no longer available as hook_update_N().
hook_update_Ndeveloper/hooks/install.phpPerform a single update.
hook_update_projects_alterdeveloper/hooks/core.phpAlter the list of projects before fetching data and comparing versions.
hook_update_status_alterdeveloper/hooks/core.phpAlter the information about available updates for projects.
hook_userdeveloper/hooks/core.phpAct on user account actions.
hook_user_operationsdeveloper/hooks/core.phpAdd mass user operations.
hook_validatedeveloper/hooks/node.phpVerify a node editing form.
hook_viewdeveloper/hooks/node.phpDisplay a node.
hook_watchdogdeveloper/hooks/core.phpLog an event message
hook_xmlrpcdeveloper/hooks/core.phpRegister XML-RPC callbacks.
module_hookincludes/module.incDetermine whether a module implements a hook.
module_implementsincludes/module.incDetermine which modules are implementing a hook.
module_invokeincludes/module.incInvoke a hook in a particular module.
module_invoke_allincludes/module.incInvoke a hook in all enabled modules that implement it.
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.