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_inboundmodules/system/system.api.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_outboundmodules/system/system.api.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_accessmodules/node/node.api.phpDefine access restrictions.
hook_actions_deletemodules/trigger/trigger.api.phpExecute code after an action is deleted.
hook_action_infomodules/trigger/trigger.api.phpDeclare information about one or more Drupal actions.
hook_action_info_altermodules/trigger/trigger.api.phpAlter the actions declared by another module.
hook_aggregator_fetchmodules/aggregator/aggregator.api.phpImplement this hook to create an alternative fetcher for aggregator module.
hook_aggregator_fetch_infomodules/aggregator/aggregator.api.phpImplement this hook to expose the title and a short description of your fetcher.
hook_aggregator_parsemodules/aggregator/aggregator.api.phpImplement this hook to create an alternative parser for aggregator module.
hook_aggregator_parse_infomodules/aggregator/aggregator.api.phpImplement this hook to expose the title and a short description of your parser.
hook_aggregator_processmodules/aggregator/aggregator.api.phpImplement this hook to create a processor for aggregator module.
hook_aggregator_process_infomodules/aggregator/aggregator.api.phpImplement this hook to expose the title and a short description of your processor.
hook_aggregator_removemodules/aggregator/aggregator.api.phpImplement this hook to remove stored data if a feed is being deleted or a feed's items are being removed.
hook_block_configuremodules/block/block.api.phpConfiguration form for the block.
hook_block_listmodules/block/block.api.phpList of all blocks defined by the module.
hook_block_list_altermodules/block/block.api.phpAct on blocks prior to rendering.
hook_block_savemodules/block/block.api.phpSave the configuration options.
hook_block_viewmodules/block/block.api.phpProcess the block when enabled in a region in order to view its contents.
hook_bootmodules/system/system.api.phpPerform setup tasks. See also, hook_init.
hook_comment_deletemodules/comment/comment.api.phpThe comment is being deleted by the moderator.
hook_comment_insertmodules/comment/comment.api.phpThe comment is being inserted.
hook_comment_publishmodules/comment/comment.api.phpThe comment is being published by the moderator.
hook_comment_unpublishmodules/comment/comment.api.phpThe comment is being unpublished by the moderator.
hook_comment_updatemodules/comment/comment.api.phpThe comment is being updated.
hook_comment_validatemodules/comment/comment.api.phpThe user has just finished editing the comment and is trying to preview or submit it. This hook can be used to check or even modify the comment. Errors should be set with form_set_error().
hook_comment_viewmodules/comment/comment.api.phpThe comment is being viewed. This hook can be used to add additional data to the comment before theming.
hook_cronmodules/system/system.api.phpPerform periodic actions.
hook_db_rewrite_sqlmodules/system/system.api.phpRewrite database queries, usually for access control.
hook_deletemodules/node/node.api.phpRespond to node deletion.
hook_disablemodules/system/system.api.phpPerform necessary actions before module is disabled.
hook_elementsmodules/system/system.api.phpAllows modules to declare their own Forms API element types and specify their default values.
hook_enablemodules/system/system.api.phpPerform necessary actions after module is enabled.
hook_exitmodules/system/system.api.phpPerform cleanup tasks.
hook_file_copymodules/system/system.api.phpRespond to a file that has been copied.
hook_file_deletemodules/system/system.api.phpRespond to a file being deleted.
hook_file_downloadmodules/system/system.api.phpControl access to private file downloads and specify HTTP headers.
hook_file_insertmodules/system/system.api.phpRespond to a file being added.
hook_file_loadmodules/system/system.api.phpLoad additional information into file objects.
hook_file_movemodules/system/system.api.phpRespond to a file that has been moved.
hook_file_referencesmodules/system/system.api.phpReport the number of times a file is referenced by a module.
hook_file_updatemodules/system/system.api.phpRespond to a file being updated.
hook_file_validatemodules/system/system.api.phpCheck that files meet a given criteria.
hook_filtermodules/filter/filter.api.phpDefine content filters.
hook_filter_tipsmodules/filter/filter.api.phpProvide tips for using filters.
hook_flush_cachesmodules/system/system.api.phpAdd a list of cache tables to be cleared.
hook_footermodules/system/system.api.phpInsert closing HTML.
hook_formmodules/node/node.api.phpDisplay a node editing form.
hook_formsmodules/system/system.api.phpMap form_ids to builder functions.
hook_form_altermodules/system/system.api.phpPerform alterations before a form is rendered.
hook_form_FORM_ID_altermodules/system/system.api.phpProvide a form-specific alteration instead of the global hook_form_alter().
hook_helpmodules/help/help.api.phpProvide online user help.
hook_hook_infomodules/trigger/trigger.api.phpExpose a list of triggers (events) that your module is allowing users to assign actions to.
hook_image_toolkitsmodules/system/system.api.phpDefine image toolkits provided by this module.
hook_initmodules/system/system.api.phpPerform setup tasks. See also, hook_boot.
hook_insertmodules/node/node.api.phpRespond to node insertion.
hook_installmodules/system/system.api.phpInstall the current version of the database schema, and any other setup tasks.
hook_js_altermodules/system/system.api.phpPerform necessary alterations to the JavaScript before it is presented on the page.
hook_linkmodules/system/system.api.phpDefine internal Drupal links.
hook_link_altermodules/system/system.api.phpPerform alterations before links on a comment 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_loadmodules/node/node.api.phpLoad node-type-specific information.
hook_localemodules/locale/locale.api.phpAllows modules to define their own text groups that can be translated.
hook_mailmodules/system/system.api.phpPrepare a message based on parameters; called from drupal_mail().
hook_mail_altermodules/system/system.api.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_menumodules/menu/menu.api.phpDefine menu items and page callbacks.
hook_menu_altermodules/menu/menu.api.phpAlter the data being saved to the {menu_router} table after hook_menu is invoked.
hook_menu_link_altermodules/menu/menu.api.phpAlter the data being saved to the {menu_links} table by menu_link_save().
hook_modules_disabledmodules/system/system.api.phpPerform necessary actions after modules are disabled.
hook_modules_enabledmodules/system/system.api.phpPerform necessary actions after modules are enabled.
hook_modules_installedmodules/system/system.api.phpPerform necessary actions after modules are installed.
hook_modules_uninstalledmodules/system/system.api.phpPerform necessary actions after modules are uninstalled.
hook_node_access_recordsmodules/node/node.api.phpSet permissions for a node to be written to the database.
hook_node_access_records_altermodules/node/node.api.phpAlter permissions for a node before it is written to the database.
hook_node_build_altermodules/node/node.api.phpThe node content was built, the module may modify the structured content.
hook_node_deletemodules/node/node.api.phpAct on node deletion.
hook_node_delete_revisionmodules/node/node.api.phpA revision of the node is deleted.
hook_node_grantsmodules/node/node.api.phpInform the node access system what permissions the user has.
hook_node_grants_altermodules/node/node.api.phpAlter user access rules when trying to view, edit or delete a node.
hook_node_infomodules/node/node.api.phpDefine module-provided node types.
hook_node_insertmodules/node/node.api.phpRespond to node insertion.
hook_node_loadmodules/node/node.api.phpAct on node objects when loaded.
hook_node_operationsmodules/node/node.api.phpAdd mass node operations.
hook_node_preparemodules/node/node.api.phpThe node is about to be shown on the add/edit form.
hook_node_prepare_translationmodules/node/node.api.phpThe node is being cloned for translation.
hook_node_presavemodules/node/node.api.phpThe node passed validation and is about to be saved.
hook_node_search_resultmodules/node/node.api.phpThe node is being displayed as a search result.
hook_node_typemodules/node/node.api.phpAct on node type changes.
hook_node_updatemodules/node/node.api.phpThe node being updated.
hook_node_update_indexmodules/node/node.api.phpThe node is being indexed.
hook_node_validatemodules/node/node.api.phpThe user has finished editing the node and is previewing or submitting it.
hook_node_viewmodules/node/node.api.phpThe node content is being assembled before rendering.
hook_openidmodules/openid/openid.api.phpAllow modules to modify the OpenID request parameters.
hook_page_altermodules/system/system.api.phpPerform alterations before a page is rendered.
hook_permmodules/system/system.api.phpDefine user permissions.
hook_preparemodules/node/node.api.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_altermodules/system/system.api.phpPerform alterations profile items before they are rendered. You may omit/add/re-sort/re-categorize, etc.
hook_query_altermodules/system/system.api.phpPerform alterations to a structured query.
hook_query_TAG_altermodules/system/system.api.phpPerform alterations to a structured query for a given tag. See alsohook_query_alter()
hook_registry_files_altermodules/system/system.api.phpPerform necessary alterations to the list of files parsed by the registry.
hook_requirementsmodules/system/system.api.phpCheck installation requirements and do status reporting.
hook_schemamodules/system/system.api.phpDefine the current version of the database schema.
hook_schema_altermodules/system/system.api.phpPerform alterations to existing database schemas.
hook_searchmodules/search/search.api.phpDefine a custom search routine.
hook_search_preprocessmodules/search/search.api.phpPreprocess text for the search index.
hook_system_info_altermodules/system/system.api.phpAlter the information parsed from module and theme .info files
hook_taxonomy_term_deletemodules/taxonomy/taxonomy.api.phpRespond to the deletion of taxonomy terms.
hook_taxonomy_term_insertmodules/taxonomy/taxonomy.api.phpAct on taxonomy terms when inserted.
hook_taxonomy_term_loadmodules/taxonomy/taxonomy.api.phpAct on taxonomy terms when loaded.
hook_taxonomy_term_updatemodules/taxonomy/taxonomy.api.phpAct on taxonomy terms when updated.
hook_taxonomy_vocabulary_deletemodules/taxonomy/taxonomy.api.phpRespond to the deletion of taxonomy vocabularies.
hook_taxonomy_vocabulary_insertmodules/taxonomy/taxonomy.api.phpAct on taxonomy vocabularies when inserted.
hook_taxonomy_vocabulary_loadmodules/taxonomy/taxonomy.api.phpAct on taxonomy vocabularies when loaded.
hook_taxonomy_vocabulary_updatemodules/taxonomy/taxonomy.api.phpAct on taxonomy vocabularies when updated.
hook_test_finishedmodules/simpletest/simpletest.api.phpAn individual test has finished.
hook_test_group_finishedmodules/simpletest/simpletest.api.phpA test group has finished.
hook_test_group_startedmodules/simpletest/simpletest.api.phpA test group has started.
hook_thememodules/system/system.api.phpRegister a module (or theme's) theme implementations.
hook_theme_registry_altermodules/system/system.api.phpAlter the theme registry information returned from hook_theme().
hook_translated_menu_link_altermodules/menu/menu.api.phpAlter a menu link after it's translated, but before it's rendered.
hook_translation_link_altermodules/locale/locale.api.phpPerform alterations on translation links.
hook_uninstallmodules/system/system.api.phpRemove any information that the module sets.
hook_updatemodules/node/node.api.phpRespond to node updating.
hook_update_indexmodules/search/search.api.phpUpdate Drupal's full-text index for this module.
hook_update_last_removedmodules/system/system.api.phpReturn a number which is no longer available as hook_update_N().
hook_update_Nmodules/system/system.api.phpPerform 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_update_projects_altermodules/update/update.api.phpAlter the list of projects before fetching data and comparing versions.
hook_update_status_altermodules/update/update.api.phpAlter the information about available updates for projects.
hook_usermodules/user/user.api.phpAct on user account actions.
hook_user_cancelmodules/user/user.api.phpAct on user account cancellations.
hook_user_cancel_methods_altermodules/user/user.api.phpModify account cancellation methods.
hook_user_categoriesmodules/user/user.api.phpRetrieve a list of all user setting/information categories.
hook_user_loadmodules/user/user.api.phpAct on user objects when loaded from the database.
hook_user_operationsmodules/user/user.api.phpAdd mass user operations.
hook_validatemodules/node/node.api.phpVerify a node editing form.
hook_viewmodules/node/node.api.phpDisplay a node.
hook_watchdogmodules/system/system.api.phpLog an event message
hook_xmlrpcmodules/system/system.api.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.
_module_implements_maintenanceincludes/module.incThis is the maintenance version of module_implements for internal use only.
 
 

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.