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 calls 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 in 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
hook_actions_deletemodules/system/system.api.phpExecutes code after an action is deleted.
hook_action_infomodules/system/system.api.phpDeclares information about actions.
hook_action_info_altermodules/system/system.api.phpAlters the actions declared by another module.
hook_admin_pathsmodules/system/system.api.phpDefine administrative paths.
hook_admin_paths_altermodules/system/system.api.phpRedefine administrative paths defined by other modules.
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_ajax_render_altermodules/system/system.api.phpAlter the commands that are sent to the user through the AJAX framework.
hook_archiver_infomodules/system/system.api.phpDeclare archivers to the system.
hook_archiver_info_altermodules/system/system.api.phpAlter archiver information declared by other modules.
hook_block_configuremodules/block/block.api.phpConfiguration form for the block.
hook_block_infomodules/block/block.api.phpDefine all blocks provided by the module.
hook_block_info_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_block_view_altermodules/block/block.api.phpPerform alterations to the content of a block.
hook_block_view_MODULE_DELTA_altermodules/block/block.api.phpPerform alterations to a specific block.
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_loadmodules/comment/comment.api.phpComments are being loaded from the database.
hook_comment_presavemodules/comment/comment.api.phpThe comment passed validation and is about to be saved.
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_viewmodules/comment/comment.api.phpThe comment is being viewed. This hook can be used to add additional data to the comment before theming.
hook_comment_view_altermodules/comment/comment.api.phpThe comment was built; the module may modify the structured content.
hook_countries_altermodules/system/system.api.phpAlter the default country list.
hook_cronmodules/system/system.api.phpPerform periodic actions.
hook_cron_queue_infomodules/system/system.api.phpDeclare queues holding items that need to be run periodically.
hook_cron_queue_info_altermodules/system/system.api.phpAlter cron queue information before cron runs.
hook_css_altermodules/system/system.api.phpAlter CSS files before they are output on the page.
hook_custom_thememodules/system/system.api.phpReturn the machine-readable name of the theme to use for the current page.
hook_dashboard_regionsmodules/dashboard/dashboard.api.phpAdds regions to the dashboard.
hook_dashboard_regions_altermodules/dashboard/dashboard.api.phpAlter dashboard regions provided by modules.
hook_date_formatsmodules/system/system.api.phpDefines additional date formats.
hook_date_formats_altermodules/system/system.api.phpAlters date types and formats declared by another module.
hook_date_format_typesmodules/system/system.api.phpDefines additional date types.
hook_deletemodules/node/node.api.phpRespond to node deletion.
hook_disablemodules/system/system.api.phpPerform necessary actions before module is disabled.
hook_drupal_goto_altermodules/system/system.api.phpChange the page the user is sent to by drupal_goto().
hook_element_infomodules/system/system.api.phpAllows modules to declare their own Forms API element types and specify their default values.
hook_element_info_altermodules/system/system.api.phpAlter the element type information returned from modules.
hook_enablemodules/system/system.api.phpPerform necessary actions after module is enabled.
hook_entity_infomodules/system/system.api.phpInform the base system and the Field API about one or more entity types.
hook_entity_info_altermodules/system/system.api.phpAlter the entity info.
hook_entity_insertmodules/system/system.api.phpAct on entities when inserted.
hook_entity_loadmodules/system/system.api.phpAct on entities when loaded.
hook_entity_prepare_viewmodules/system/system.api.phpAct on entities as they are being prepared for view.
hook_entity_updatemodules/system/system.api.phpAct on entities when updated.
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_mimetype_mapping_altermodules/system/system.api.phpAlter MIME type mappings used to determine MIME type from a file extension.
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_url_altermodules/system/system.api.phpAlter the URL to a file.
hook_file_validatemodules/system/system.api.phpCheck that files meet a given criteria.
hook_filter_format_deletemodules/filter/filter.api.phpPerform actions when a text format has been deleted.
hook_filter_format_insertmodules/filter/filter.api.phpPerform actions when a new text format has been created.
hook_filter_format_updatemodules/filter/filter.api.phpPerform actions when a text format has been updated.
hook_filter_infomodules/filter/filter.api.phpDefine content filters.
hook_filter_info_altermodules/filter/filter.api.phpPerform alterations on filter definitions.
hook_flush_cachesmodules/system/system.api.phpAdd a list of cache tables to be cleared.
hook_formmodules/node/node.api.phpDisplay a node editing form.
hook_formsmodules/system/system.api.phpMap form_ids to form 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/system/system.api.phpDefines one or more hooks that are exposed by a module.
hook_html_head_altermodules/system/system.api.phpAlter XHTML HEAD tags before they are rendered by drupal_get_html_head().
hook_image_default_stylesmodules/image/image.api.phpProvide module-based image styles for reuse throughout Drupal.
hook_image_effect_infomodules/image/image.api.phpDefine information about image effects provided by a module.
hook_image_styles_altermodules/image/image.api.phpModify any image styles provided by other modules or the user.
hook_image_style_deletemodules/image/image.api.phpRespond to image style deletion.
hook_image_style_flushmodules/image/image.api.phpRespond to image style flushing.
hook_image_style_savemodules/image/image.api.phpRespond to image style updating.
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 creation of a new node.
hook_installmodules/system/system.api.phpPerform setup tasks when the module is installed.
hook_install_tasksmodules/system/system.api.phpReturn an array of tasks to be performed by an installation profile.
hook_install_tasks_altermodules/system/system.api.phpAlter the full list of installation tasks.
hook_js_altermodules/system/system.api.phpPerform necessary alterations to the JavaScript before it is presented on the page.
hook_language_fallback_candidates_altermodules/locale/locale.api.phpPerform alterations on the language fallback candidates.
hook_language_negotiation_infomodules/locale/locale.api.phpAllow modules to define their own language providers.
hook_language_negotiation_info_altermodules/locale/locale.api.phpPerform alterations on language providers.
hook_language_switch_links_altermodules/locale/locale.api.phpPerform alterations on language switcher links.
hook_language_types_infomodules/locale/locale.api.phpAllow modules to define their own language types.
hook_language_types_info_altermodules/locale/locale.api.phpPerform alterations on language types.
hook_librarymodules/system/system.api.phpRegisters JavaScript/CSS libraries associated with a module.
hook_library_altermodules/system/system.api.phpAlters the JavaScript/CSS library registry.
hook_loadmodules/node/node.api.phpAct on nodes being loaded from the database.
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 an email message created with the drupal_mail() function.
hook_menumodules/menu/menu.api.phpDefine menu items and page callbacks.
hook_menu_active_handler_altermodules/system/system.api.phpAlters the router item for the active menu handler.
hook_menu_altermodules/menu/menu.api.phpAlter the data being saved to the {menu_router} table after hook_menu is invoked.
hook_menu_contextual_links_altermodules/menu/menu.api.phpAlter contextual links before they are rendered.
hook_menu_deletemodules/menu/menu.api.phpInforms modules that a custom menu was deleted.
hook_menu_insertmodules/menu/menu.api.phpInforms modules that a custom menu was created.
hook_menu_link_altermodules/menu/menu.api.phpAlter the data being saved to the {menu_links} table by menu_link_save().
hook_menu_link_deletemodules/menu/menu.api.phpInform modules that a menu link has been deleted.
hook_menu_link_insertmodules/menu/menu.api.phpInform modules that a menu link has been created.
hook_menu_link_updatemodules/menu/menu.api.phpInform modules that a menu link has been updated.
hook_menu_local_tasks_altermodules/menu/menu.api.phpAlter tabs and actions displayed on the page before they are rendered.
hook_menu_updatemodules/menu/menu.api.phpInforms modules that a custom menu was updated.
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_multilingual_settings_changedmodules/locale/locale.api.phpAllow modules to react to language settings changes.
hook_node_accessmodules/node/node.api.phpControl access to a node.
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_deletemodules/node/node.api.phpRespond to node deletion.
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 creation of a new node.
hook_node_loadmodules/node/node.api.phpAct on nodes being loaded from the database.
hook_node_operationsmodules/node/node.api.phpAdd mass node operations.
hook_node_preparemodules/node/node.api.phpAct on a node object about to be shown on the add/edit form.
hook_node_prepare_translationmodules/node/node.api.phpAct on a node object being cloned for translation.
hook_node_presavemodules/node/node.api.phpAct on a node being inserted or updated.
hook_node_revision_deletemodules/node/node.api.phpRespond to deletion of a node revision.
hook_node_search_resultmodules/node/node.api.phpAct on a node being displayed as a search result.
hook_node_type_deletemodules/node/node.api.phpRespond to node type deletion.
hook_node_type_insertmodules/node/node.api.phpRespond to node type creation.
hook_node_type_updatemodules/node/node.api.phpRespond to node type updates.
hook_node_updatemodules/node/node.api.phpRespond to updates to a node.
hook_node_update_indexmodules/node/node.api.phpAct on a node being indexed for searching.
hook_node_validatemodules/node/node.api.phpPerform node validation before a node is created or updated.
hook_node_viewmodules/node/node.api.phpAct on a node that is being assembled before rendering.
hook_node_view_altermodules/node/node.api.phpAlter the results of node_view().
hook_openidmodules/openid/openid.api.phpAllow modules to modify the OpenID request parameters.
hook_openid_discovery_method_infomodules/openid/openid.api.phpAllow modules to declare OpenID discovery methods.
hook_openid_discovery_method_info_altermodules/openid/openid.api.phpAllow modules to alter discovery methods.
hook_openid_normalization_method_infomodules/openid/openid.api.phpAllow modules to declare OpenID normalization methods.
hook_openid_normalization_method_info_altermodules/openid/openid.api.phpAllow modules to alter normalization methods.
hook_openid_responsemodules/openid/openid.api.phpAllow modules to act upon a successful OpenID login.
hook_overlay_child_initializemodules/overlay/overlay.api.phpAllow modules to act when an overlay child window is initialized.
hook_overlay_parent_initializemodules/overlay/overlay.api.phpAllow modules to act when an overlay parent window is initialized.
hook_page_altermodules/system/system.api.phpPerform alterations before a page is rendered.
hook_page_buildmodules/system/system.api.phpAdd elements to a page before it is rendered.
hook_page_delivery_callback_altermodules/system/system.api.phpAlters the delivery callback used to send the result of the page callback to the browser.
hook_path_deletemodules/path/path.api.phpThe path has been deleted.
hook_path_insertmodules/path/path.api.phpThe path has been inserted.
hook_path_updatemodules/path/path.api.phpThe path has been updated.
hook_permissionmodules/system/system.api.phpDefine user permissions.
hook_preparemodules/node/node.api.phpAct on a node object about to be shown on the add/edit form.
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.
hook_rankingmodules/node/node.api.phpProvide additional methods of scoring for core search results for nodes.
hook_rdf_mappingmodules/rdf/rdf.api.phpAllow modules to define RDF mappings for field bundles.
hook_rdf_namespacesmodules/rdf/rdf.api.phpAllow modules to define namespaces for RDF mappings.
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_search_accessmodules/search/search.api.phpDefine access to a custom search routine.
hook_search_adminmodules/search/search.api.phpAdd elements to the search settings form.
hook_search_executemodules/search/search.api.phpExecute a search for a set of key words.
hook_search_infomodules/search/search.api.phpDefine a custom search type.
hook_search_pagemodules/search/search.api.phpOverride the rendering of search results.
hook_search_preprocessmodules/search/search.api.phpPreprocess text for search.
hook_search_resetmodules/search/search.api.phpTake action when the search index is going to be rebuilt.
hook_search_statusmodules/search/search.api.phpReport the status of indexing.
hook_shortcut_default_setmodules/shortcut/shortcut.api.phpReturn the name of a default shortcut set for the provided user account.
hook_simpletest_altermodules/simpletest/simpletest.api.phpAlter the list of tests.
hook_stream_wrappersmodules/system/system.api.phpRegisters PHP stream wrapper implementations associated with a module.
hook_stream_wrappers_altermodules/system/system.api.phpAlters the list of PHP stream wrapper implementations.
hook_system_info_altermodules/system/system.api.phpAlter the information parsed from module and theme .info files
hook_system_themes_page_altermodules/system/system.api.phpAlters theme operation links.
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_tokensmodules/system/system.api.phpProvide replacement values for placeholder tokens.
hook_token_infomodules/system/system.api.phpProvide metadata about available placeholder tokens and token types.
hook_token_info_altermodules/system/system.api.phpAlter the metadata about available placeholder tokens and token types.
hook_translated_menu_link_altermodules/menu/menu.api.phpAlter a menu link after it's translated, but before it's rendered.
hook_trigger_infomodules/trigger/trigger.api.phpDeclares triggers (events) for users to assign actions to.
hook_uninstallmodules/system/system.api.phpRemove any information that the module sets.
hook_updatemodules/node/node.api.phpRespond to updates to a node.
hook_update_dependenciesmodules/system/system.api.phpReturn an array of information about module update dependencies.
hook_update_indexmodules/search/search.api.phpUpdate the search 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.
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_upgradessites/all/modules/coder/coder_upgrade/coder_upgrade.api.phpDeclare upgrade sets for an API (or set of APIs).
hook_url_inbound_altermodules/system/system.api.phpAlters inbound URL requests.
hook_url_outbound_altermodules/system/system.api.phpAlters outbound URLs.
hook_username_altermodules/system/system.api.phpAlter the username that is displayed for a user.
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_deletemodules/user/user.api.phpRespond to user deletion.
hook_user_insertmodules/user/user.api.phpA user account was created.
hook_user_loadmodules/user/user.api.phpAct on user objects when loaded from the database.
hook_user_loginmodules/user/user.api.phpThe user just logged in.
hook_user_logoutmodules/user/user.api.phpThe user just logged out.
hook_user_operationsmodules/user/user.api.phpAdd mass user operations.
hook_user_presavemodules/user/user.api.phpA user account is about to be created or updated.
hook_user_role_deletemodules/user/user.api.phpInform other modules that a user role has been deleted.
hook_user_role_insertmodules/user/user.api.phpInform other modules that a user role has been added.
hook_user_role_updatemodules/user/user.api.phpInform other modules that a user role has been updated.
hook_user_updatemodules/user/user.api.phpA user account was updated.
hook_user_viewmodules/user/user.api.phpThe user's account information is being displayed.
hook_user_view_altermodules/user/user.api.phpThe user was built; the module may modify the structured content.
hook_validatemodules/node/node.api.phpPerform node validation before a node is created or updated.
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.
hook_xmlrpc_altermodules/system/system.api.phpAlter the definition of XML-RPC methods before they are called.
module_hookincludes/module.incDetermine whether a module implements a hook.
module_hook_infoincludes/module.incRetrieve a list of what hooks are explicitly declared.
module_implementsincludes/module.incDetermine which modules are implementing a hook.
module_implements_write_cacheincludes/module.incWrites the hook implementation cache.
module_invokeincludes/module.incInvoke a hook in a particular module.
module_invoke_allincludes/module.incInvoke a hook in all enabled modules that implement it.