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 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().

The example functions included are not part of the Drupal core, they are just models that you can modify. Only the hooks implemented within modules are executed when running Drupal.

See also the themeable group page.

Groups

NameDescription
Field Formatter APIDefine Field API formatter types.
Field Types APIDefine field types.
Field Widget APIDefine Field API widget types.

Functions & methods

NameDescription
hook_actions_deleteExecutes code after an action is deleted.
hook_action_infoDeclares information about actions.
hook_action_info_alterAlters the actions declared by another module.
hook_admin_pathsDefine administrative paths.
hook_admin_paths_alterRedefine administrative paths defined by other modules.
hook_aggregator_fetchCreate an alternative fetcher for aggregator.module.
hook_aggregator_fetch_infoSpecify the title and short description of your fetcher.
hook_aggregator_parseCreate an alternative parser for aggregator module.
hook_aggregator_parse_infoSpecify the title and short description of your parser.
hook_aggregator_processCreate a processor for aggregator.module.
hook_aggregator_process_infoSpecify the title and short description of your processor.
hook_aggregator_removeRemove stored feed data.
hook_ajax_render_alterAlter the commands that are sent to the user through the Ajax framework.
hook_archiver_infoDeclare archivers to the system.
hook_archiver_info_alterAlter archiver information declared by other modules.
hook_batch_alterAlter batch information before a batch is processed.
hook_block_configureDefine a configuration form for a block.
hook_block_infoDefine all blocks provided by the module.
hook_block_info_alterChange block definition before saving to the database.
hook_block_list_alterAct on blocks prior to rendering.
hook_block_saveSave the configuration options from hook_block_configure().
hook_block_viewReturn a rendered or renderable view of a block.
hook_block_view_alterPerform alterations to the content of a block.
hook_block_view_MODULE_DELTA_alterPerform alterations to a specific block.
hook_bootPerform setup tasks for all page requests.
hook_comment_deleteThe comment is being deleted by the moderator.
hook_comment_insertThe comment is being inserted.
hook_comment_loadComments are being loaded from the database.
hook_comment_presaveThe comment passed validation and is about to be saved.
hook_comment_publishThe comment is being published by the moderator.
hook_comment_unpublishThe comment is being unpublished by the moderator.
hook_comment_updateThe comment is being updated.
hook_comment_viewThe comment is being viewed. This hook can be used to add additional data to the comment before theming.
hook_comment_view_alterThe comment was built; the module may modify the structured content.
hook_contextual_links_view_alterAlter a contextual links element before it is rendered.
hook_countries_alterAlter the default country list.
hook_cronPerform periodic actions.
hook_cron_queue_infoDeclare queues holding items that need to be run periodically.
hook_cron_queue_info_alterAlter cron queue information before cron runs.
hook_css_alterAlter CSS files before they are output on the page.
hook_custom_themeReturn the machine-readable name of the theme to use for the current page.
hook_dashboard_regionsAdd regions to the dashboard.
hook_dashboard_regions_alterAlter dashboard regions provided by modules.
hook_date_formatsDefine additional date formats.
hook_date_formats_alterAlter date formats declared by another module.
hook_date_format_typesDefine additional date types.
hook_date_format_types_alterModify existing date types.
hook_deleteRespond to node deletion.
hook_disablePerform necessary actions before module is disabled.
hook_drupal_goto_alterChange the page the user is sent to by drupal_goto().
hook_element_infoAllows modules to declare their own Forms API element types and specify their default values.
hook_element_info_alterAlter the element type information returned from modules.
hook_enablePerform necessary actions after module is enabled.
hook_entity_deleteAct on entities when deleted.
hook_entity_infoInform the base system and the Field API about one or more entity types.
hook_entity_info_alterAlter the entity info.
hook_entity_insertAct on entities when inserted.
hook_entity_loadAct on entities when loaded.
hook_entity_prepare_viewAct on entities as they are being prepared for view.
hook_entity_presaveAct on an entity before it is about to be created or updated.
hook_entity_query_alterAlter or execute an EntityFieldQuery.
hook_entity_updateAct on entities when updated.
hook_entity_viewAct on entities being assembled before rendering.
hook_entity_view_alterAlter the results of ENTITY_view().
hook_exitPerform cleanup tasks.
hook_field_accessDetermine whether the user has access to a given field.
hook_field_attach_create_bundleAct on field_attach_create_bundle().
hook_field_attach_deleteAct on field_attach_delete().
hook_field_attach_delete_bundleAct on field_attach_delete_bundle.
hook_field_attach_delete_revisionAct on field_attach_delete_revision().
hook_field_attach_formAct on field_attach_form().
hook_field_attach_insertAct on field_attach_insert().
hook_field_attach_loadAct on field_attach_load().
hook_field_attach_prepare_translation_alterPerform alterations on field_attach_prepare_translation().
hook_field_attach_preprocess_alterAlter field_attach_preprocess() variables.
hook_field_attach_presaveAct on field_attach_presave().
hook_field_attach_purgeAct on field_purge_data().
hook_field_attach_rename_bundleAct on field_attach_rename_bundle().
hook_field_attach_submitAct on field_attach_submit().
hook_field_attach_updateAct on field_attach_update().
hook_field_attach_validateAct on field_attach_validate().
hook_field_attach_view_alterPerform alterations on field_attach_view() or field_view_field().
hook_field_available_languages_alterAlter field_available_languages() values.
hook_field_create_fieldAct on a field being created.
hook_field_create_instanceAct on a field instance being created.
hook_field_deleteDefine custom delete behavior for this module's field data.
hook_field_delete_fieldAct on a field being deleted.
hook_field_delete_instanceAct on a field instance being deleted.
hook_field_delete_revisionDefine custom revision delete behavior for this module's field types.
hook_field_display_alterAlters the display settings of a field before it gets displayed.
hook_field_display_ENTITY_TYPE_alterAlters the display settings of a field on a given entity type before it gets displayed.
hook_field_extra_fieldsExposes "pseudo-field" components on fieldable entities.
hook_field_extra_fields_alterAlter "pseudo-field" components on fieldable entities.
hook_field_extra_fields_display_alterAlters the display settings of pseudo-fields before an entity is displayed.
hook_field_formatter_infoExpose Field API formatter types.
hook_field_formatter_info_alterPerform alterations on Field API formatter types.
hook_field_formatter_prepare_viewAllow formatters to load information for field values being displayed.
hook_field_formatter_viewBuild a renderable array for a field value.
hook_field_infoDefine Field API field types.
hook_field_info_alterPerform alterations on Field API field types.
hook_field_info_max_weightReturns the maximum weight for the entity components handled by the module.
hook_field_insertDefine custom insert behavior for this module's field data.
hook_field_is_emptyDefine what constitutes an empty item for a field type.
hook_field_language_alterPerform alterations on field_language() values.
hook_field_loadDefine custom load behavior for this module's field types.
hook_field_prepare_translationDefine custom prepare_translation behavior for this module's field types.
hook_field_prepare_viewPrepare field values prior to display.
hook_field_presaveDefine custom presave behavior for this module's field types.
hook_field_purge_fieldActs when a field record is being purged.
hook_field_purge_instanceActs when a field instance is being purged.
hook_field_read_fieldAct on field records being read from the database.
hook_field_read_instanceAct on a field record being read from the database.
hook_field_schemaDefine the Field API schema for a field structure.
hook_field_storage_create_fieldAct on creation of a new field.
hook_field_storage_deleteDelete all field data for an entity.
hook_field_storage_delete_fieldAct on deletion of a field.
hook_field_storage_delete_instanceAct on deletion of a field instance.
hook_field_storage_delete_revisionDelete a single revision of field data for an entity.
hook_field_storage_detailsReveal the internal details about the storage for a field.
hook_field_storage_details_alterPerform alterations on Field API storage details.
hook_field_storage_infoExpose Field API storage backends.
hook_field_storage_info_alterPerform alterations on Field API storage types.
hook_field_storage_loadLoad field data for a set of entities.
hook_field_storage_pre_insertAct before the storage backends insert field data.
hook_field_storage_pre_loadAct before the storage backends load field data.
hook_field_storage_pre_updateAct before the storage backends update field data.
hook_field_storage_purgeRemove field storage information when field data is purged.
hook_field_storage_purge_fieldRemove field storage information when a field record is purged.
hook_field_storage_purge_field_instanceRemove field storage information when a field instance is purged.
hook_field_storage_queryExecute an EntityFieldQuery.
hook_field_storage_update_fieldUpdate the storage information for a field.
hook_field_storage_writeWrite field data for an entity.
hook_field_updateDefine custom update behavior for this module's field data.
hook_field_update_fieldAct on a field being updated.
hook_field_update_forbidForbid a field update from occurring.
hook_field_update_instanceAct on a field instance being updated.
hook_field_validateValidate this module's field data.
hook_field_widget_errorFlag a field-level validation error.
hook_field_widget_formReturn the form for a single field widget.
hook_field_widget_form_alterAlter forms for field widgets provided by other modules.
hook_field_widget_infoExpose Field API widget types.
hook_field_widget_info_alterPerform alterations on Field API widget types.
hook_field_widget_properties_alterAlters the widget properties of a field instance before it gets displayed.
hook_field_widget_properties_ENTITY_TYPE_alterAlters the widget properties of a field instance on a given entity type before it gets displayed.
hook_field_widget_WIDGET_TYPE_form_alterAlter widget forms for a specific widget provided by another module.
hook_filetransfer_infoRegister information about FileTransfer classes provided by a module.
hook_filetransfer_info_alterAlter the FileTransfer class registry.
hook_file_copyRespond to a file that has been copied.
hook_file_deleteRespond to a file being deleted.
hook_file_downloadControl access to private file downloads and specify HTTP headers.
hook_file_insertRespond to a file being added.
hook_file_loadLoad additional information into file objects.
hook_file_mimetype_mapping_alterAlter MIME type mappings used to determine MIME type from a file extension.
hook_file_moveRespond to a file that has been moved.
hook_file_presaveAct on a file being inserted or updated.
hook_file_updateRespond to a file being updated.
hook_file_url_alterAlter the URL to a file.
hook_file_validateCheck that files meet a given criteria.
hook_filter_format_disablePerform actions when a text format has been disabled.
hook_filter_format_insertPerform actions when a new text format has been created.
hook_filter_format_updatePerform actions when a text format has been updated.
hook_filter_infoDefine content filters.
hook_filter_info_alterPerform alterations on filter definitions.
hook_flush_cachesAdd a list of cache tables to be cleared.
hook_formDisplay a node editing form.
hook_formsMap form_ids to form builder functions.
hook_form_alterPerform alterations before a form is rendered.
hook_form_BASE_FORM_ID_alterProvide a form-specific alteration for shared ('base') forms.
hook_form_FORM_ID_alterProvide a form-specific alteration instead of the global hook_form_alter().
hook_helpProvide online user help.
hook_hook_infoDefines one or more hooks that are exposed by a module.
hook_hook_info_alterAlter information from hook_hook_info().
hook_html_head_alterAlter XHTML HEAD tags before they are rendered by drupal_get_html_head().
hook_image_default_stylesProvide module-based image styles for reuse throughout Drupal.
hook_image_effect_infoDefine information about image effects provided by a module.
hook_image_effect_info_alterAlter the information provided in hook_image_effect_info().
hook_image_styles_alterModify any image styles provided by other modules or the user.
hook_image_style_deleteRespond to image style deletion.
hook_image_style_flushRespond to image style flushing.
hook_image_style_saveRespond to image style updating.
hook_image_toolkitsDefine image toolkits provided by this module.
hook_initPerform setup tasks for non-cached page requests.
hook_insertRespond to creation of a new node.
hook_installPerform setup tasks when the module is installed.
hook_install_tasksReturn an array of tasks to be performed by an installation profile.
hook_install_tasks_alterAlter the full list of installation tasks.
hook_js_alterPerform necessary alterations to the JavaScript before it is presented on the page.
hook_language_fallback_candidates_alterPerform alterations on the language fallback candidates.
hook_language_initAllows modules to act after language initialization has been performed.
hook_language_negotiation_infoAllow modules to define their own language providers.
hook_language_negotiation_info_alterPerform alterations on language providers.
hook_language_switch_links_alterPerform alterations on language switcher links.
hook_language_types_infoAllow modules to define their own language types.
hook_language_types_info_alterPerform alterations on language types.
hook_libraryRegisters JavaScript/CSS libraries associated with a module.
hook_library_alterAlters the JavaScript/CSS library registry.
hook_loadAct on nodes being loaded from the database.
hook_localeAllows modules to define their own text groups that can be translated.
hook_mailPrepare a message based on parameters; called from drupal_mail().
hook_mail_alterAlter an email message created with the drupal_mail() function.
hook_menuDefine menu items and page callbacks.
hook_menu_alterAlter the data being saved to the {menu_router} table after hook_menu is invoked.
hook_menu_breadcrumb_alterAlter links in the active trail before it is rendered as the breadcrumb.
hook_menu_contextual_links_alterAlter contextual links before they are rendered.
hook_menu_deleteInforms modules that a custom menu was deleted.
hook_menu_get_item_alterAlter a menu router item right after it has been retrieved from the database or cache.
hook_menu_insertInforms modules that a custom menu was created.
hook_menu_link_alterAlter the data being saved to the {menu_links} table by menu_link_save().
hook_menu_link_deleteInform modules that a menu link has been deleted.
hook_menu_link_insertInform modules that a menu link has been created.
hook_menu_link_updateInform modules that a menu link has been updated.
hook_menu_local_tasks_alterAlter tabs and actions displayed on the page before they are rendered.
hook_menu_site_status_alterControl site status before menu dispatching.
hook_menu_updateInforms modules that a custom menu was updated.
hook_modules_disabledPerform necessary actions after modules are disabled.
hook_modules_enabledPerform necessary actions after modules are enabled.
hook_modules_installedPerform necessary actions after modules are installed.
hook_modules_uninstalledPerform necessary actions after modules are uninstalled.
hook_module_implements_alterAlter the registry of modules implementing a hook.
hook_multilingual_settings_changedAllow modules to react to language settings changes.
hook_node_accessControl access to a node.
hook_node_access_recordsSet permissions for a node to be written to the database.
hook_node_access_records_alterAlter permissions for a node before it is written to the database.
hook_node_deleteRespond to node deletion.
hook_node_grantsInform the node access system what permissions the user has.
hook_node_grants_alterAlter user access rules when trying to view, edit or delete a node.
hook_node_infoDefine module-provided node types.
hook_node_insertRespond to creation of a new node.
hook_node_loadAct on nodes being loaded from the database.
hook_node_operationsAdd mass node operations.
hook_node_prepareAct on a node object about to be shown on the add/edit form.
hook_node_presaveAct on a node being inserted or updated.
hook_node_revision_deleteRespond to deletion of a node revision.
hook_node_search_resultAct on a node being displayed as a search result.
hook_node_submitAct on a node after validated form values have been copied to it.
hook_node_type_deleteRespond to node type deletion.
hook_node_type_insertRespond to node type creation.
hook_node_type_updateRespond to node type updates.
hook_node_updateRespond to updates to a node.
hook_node_update_indexAct on a node being indexed for searching.
hook_node_validatePerform node validation before a node is created or updated.
hook_node_viewAct on a node that is being assembled before rendering.
hook_node_view_alterAlter the results of node_view().
hook_openidAllow modules to modify the OpenID request parameters.
hook_openid_discovery_method_infoAllow modules to declare OpenID discovery methods.
hook_openid_discovery_method_info_alterAllow modules to alter discovery methods.
hook_openid_normalization_method_infoAllow modules to declare OpenID normalization methods.
hook_openid_normalization_method_info_alterAllow modules to alter normalization methods.
hook_openid_responseAllow modules to act upon a successful OpenID login.
hook_overlay_child_initializeAllow modules to act when an overlay child window is initialized.
hook_overlay_parent_initializeAllow modules to act when an overlay parent window is initialized.
hook_page_alterPerform alterations before a page is rendered.
hook_page_buildAdd elements to a page before it is rendered.
hook_page_delivery_callback_alterAlters the delivery callback used to send the result of the page callback to the browser.
hook_path_deleteRespond to a path being deleted.
hook_path_insertRespond to a path being inserted.
hook_path_updateRespond to a path being updated.
hook_permissionDefine user permissions.
hook_prepareAct on a node object about to be shown on the add/edit form.
hook_query_alterPerform alterations to a structured query.
hook_query_TAG_alterPerform alterations to a structured query for a given tag.
hook_rankingProvide additional methods of scoring for core search results for nodes.
hook_rdf_mappingAllow modules to define RDF mappings for field bundles.
hook_rdf_namespacesAllow modules to define namespaces for RDF mappings.
hook_registry_files_alterPerform necessary alterations to the list of files parsed by the registry.
hook_requirementsCheck installation requirements and do status reporting.
hook_schemaDefine the current version of the database schema.
hook_schema_alterPerform alterations to existing database schemas.
hook_search_accessDefine access to a custom search routine.
hook_search_adminAdd elements to the search settings form.
hook_search_executeExecute a search for a set of key words.
hook_search_infoDefine a custom search type.
hook_search_pageOverride the rendering of search results.
hook_search_preprocessPreprocess text for search.
hook_search_resetTake action when the search index is going to be rebuilt.
hook_search_statusReport the status of indexing.
hook_shortcut_default_setReturn the name of a default shortcut set for the provided user account.
hook_simpletest_alterAlter the list of tests.
hook_stream_wrappersRegisters PHP stream wrapper implementations associated with a module.
hook_stream_wrappers_alterAlters the list of PHP stream wrapper implementations.
hook_system_info_alterAlter the information parsed from module and theme .info files
hook_system_themes_page_alterAlters theme operation links.
hook_system_theme_infoReturn additional themes provided by modules.
hook_taxonomy_term_deleteRespond to the deletion of taxonomy terms.
hook_taxonomy_term_insertAct on taxonomy terms when inserted.
hook_taxonomy_term_loadAct on taxonomy terms when loaded.
hook_taxonomy_term_presaveAct on taxonomy terms before they are saved.
hook_taxonomy_term_updateAct on taxonomy terms when updated.
hook_taxonomy_term_view_alterAlter the results of taxonomy_term_view().
hook_taxonomy_vocabulary_deleteRespond to the deletion of taxonomy vocabularies.
hook_taxonomy_vocabulary_insertAct on taxonomy vocabularies when inserted.
hook_taxonomy_vocabulary_loadAct on taxonomy vocabularies when loaded.
hook_taxonomy_vocabulary_presaveAct on taxonomy vocabularies before they are saved.
hook_taxonomy_vocabulary_updateAct on taxonomy vocabularies when updated.
hook_test_finishedAn individual test has finished.
hook_test_group_finishedA test group has finished.
hook_test_group_startedA test group has started.
hook_themeRegister a module (or theme's) theme implementations.
hook_theme_registry_alterAlter the theme registry information returned from hook_theme().
hook_tokensProvide replacement values for placeholder tokens.
hook_tokens_alterAlter replacement values for placeholder tokens.
hook_token_infoProvide information about available placeholder tokens and token types.
hook_token_info_alterAlter the metadata about available placeholder tokens and token types.
hook_translated_menu_link_alterAlter a menu link after it has been translated and before it is rendered.
hook_trigger_infoDeclare triggers (events) for users to assign actions to.
hook_trigger_info_alterAlter triggers declared by hook_trigger_info().
hook_uninstallRemove any information that the module sets.
hook_updateRespond to updates to a node.
hook_updater_infoProvide information on Updaters (classes that can update Drupal).
hook_updater_info_alterAlter the Updater information array.
hook_update_dependenciesReturn an array of information about module update dependencies.
hook_update_indexUpdate the search index for this module.
hook_update_last_removedReturn a number which is no longer available as hook_update_N().
hook_update_NPerform a single update.
hook_update_projects_alterAlter the list of projects before fetching data and comparing versions.
hook_update_status_alterAlter the information about available updates for projects.
hook_url_inbound_alterAlters inbound URL requests.
hook_url_outbound_alterAlters outbound URLs.
hook_username_alterAlter the username that is displayed for a user.
hook_user_cancelAct on user account cancellations.
hook_user_cancel_methods_alterModify account cancellation methods.
hook_user_categoriesRetrieve a list of user setting or profile information categories.
hook_user_deleteRespond to user deletion.
hook_user_insertA user account was created.
hook_user_loadAct on user objects when loaded from the database.
hook_user_loginThe user just logged in.
hook_user_logoutThe user just logged out.
hook_user_operationsAdd mass user operations.
hook_user_presaveA user account is about to be created or updated.
hook_user_role_deleteInform other modules that a user role has been deleted.
hook_user_role_insertInform other modules that a user role has been added.
hook_user_role_presaveInform other modules that a user role is about to be saved.
hook_user_role_updateInform other modules that a user role has been updated.
hook_user_updateA user account was updated.
hook_user_viewThe user's account information is being displayed.
hook_user_view_alterThe user was built; the module may modify the structured content.
hook_validatePerform node validation before a node is created or updated.
hook_verify_update_archiveVerify an archive after it has been downloaded and extracted.
hook_viewDisplay a node.
hook_watchdogLog an event message.
hook_xmlrpcRegister XML-RPC callbacks.
hook_xmlrpc_alterAlters the definition of XML-RPC methods before they are called.
module_hookDetermine whether a module implements a hook.
module_hook_infoRetrieve a list of what hooks are explicitly declared.
module_implementsDetermine which modules are implementing a hook.
module_implements_write_cacheWrites the hook implementation cache.
module_invokeInvoke a hook in a particular module.
module_invoke_allInvoke a hook in all enabled modules that implement it.
sample_search_conditions_callbackAn example conditions callback function for search.

File

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

Login or register to post comments