
Drupal Modules are based on the concept called hooks. The “Hooks” are nothing but a PHP function. The naming convention is more important when we using hooks. The hooks are named like “hook_block”, ”hook_delete” etc. If we want to implement Drupal hook in our module, we need to create a PHP function with the name moduleName_hookName” where “moduleName” is the name of our module and “hookName” is the name of the hook such as “block”, “delete”, etc. To be more precise the string “hook” is used just as a placeholder for the module name.
For Example
We have a module named “custom_module” (filenae : custom_module.module ), if we want to implement hook “hook_block”, we need to create a PHP function in our module with the name “custom_module_block”, here custom_module is our module name and block is hook name.
Each hook has a defined set of parameters and a specified result type. Drupal hooks can be used to extend Drupal functionality, or customizing certain functionality. Suppose we want to send an email to all registered users when we creating a post with a new topic, we can use Drupal hooks to implement this functionality.Here is the list of Drupal hooks…
NameDescription
hook_access($op, $node, $account)
Define access restrictions.
hook_actions_delete()
Execute code after an action is deleted.
hook_auth
Verify authentication of a user.
hook_block($op=’list’, $delta=0, $edit=array())
Declare a block or set of blocks.
hook_boot()
Perform setup tasks. See also, hook_init.
hook_comment
Act on comments.
hook_cron
Perform periodic actions.
hook_db_rewrite_sql($query, $primary_table, $primary_field, $args)
Add 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 vocabulariesit is vid. For comments, it is cid. Primary…
hook_delete
Respond to node deletion.
hook_disable()
Perform necessary actions before module is disabled.
hook_elements
Allows modules to declare their own form element types and specify their default values.
hook_enable()
Perform necessary actions after module is enabled.
hook_exit($destination=NULL)
Perform cleanup tasks.
hook_file_download($file)
Allow file downloads.
hook_filter($op, $delta=0, $format=-1, $text=”)
Define content filters.
hook_filter_tips($delta, $format, $long=false)
Provide tips for using filters.
hook_flush_caches()
Add a list of cache tables to be cleared.
hook_footer($main=0)
Insert closing HTML.
hook_form(&$node,&$param)
Display a node editing form.
hook_forms()
Map form_ids to builder functions.
hook_form_alter(&$form,$form_state,$form_id)
Perform alterations before a form is rendered. One popular use of this hook is to add form elements tothe node form.
hook_help($path, $arg)
Provide online user help.
hook_info
Declare authentication scheme information.
hook_init
Perform setup tasks.
hook_insert($node)
Respond to node insertion.
hook_install
Install the current version of the database schema.
hook_link($type, $object, $teaser=FALSE)
Define internal Drupal links.
hook_link_alter(&$links, $node)
Perform alterations before links on a node are rendered. One popular use of this hook is to add/deletelinks from other modules.
hook_load($node)
Load node-type-specific information.
hook_mail($key, &$message, $params)
Prepare a message based on parameters. See drupal_mail for more.
hook_mail_alter(&$message)
Alter any aspect of the emails sent by Drupal.
hook_menu
Define menu items and page callbacks.
hook_menu_alter(&$callbacks)
Alter the data being saved to the {menu_router} table after hook_menu is invoked.
hook_menu_link_alter(&$item, $menu)
Alter the data being saved to the {menu_links} table by menu_link_save().
hook_nodeapi(&$node, $op, $a3=NULL, $a4=NULL)
Act on nodes defined by other modules.
hook_node_grants($account, $op)
Grant access to nodes.
hook_node_info
Define the human-readable name of a node type.
hook_node_operations()
Add mass node operations.
hook_node_type($op, $info)
Act on node type changes.
hook_perm
Define user permissions.
hook_ping($name=”, $url=”)
Ping another server.
hook_prepare(&$node)
This is a hook used by node modules. It is called after load but before the node is shown on theadd/edit form.
hook_profile_alter(&$fields, $account)
Perform alterations profile items before they are rendered. You may omit/add/re-sort/recategorize, etc.
hook_requirements($phase)
Check installation requirements and do status reporting.
hook_schema()
Define the current version of the database schema.
hook_search($op=’search’, $keys=null)
Define a custom search routine.
hook_search_item($item)
Format a search result.
hook_search_preprocess($text)
Preprocess text for the search index.
hook_submit(&$node)
This is a hook used by node modules. It is called after validation has succeeded and beforeinsert/update. It is used to for actions which must happen only if the node is to be saved.
hook_settings
Declare administrative settings for a module.
hook_system_info_alter()
Alert the information parsed from modules and theme .info files
hook_taxonomy($op, $type, $array=NULL)
Act on taxonomy changes.
hook_term_path()
Allows modules to provide an alternative path for the terms it manages.
hook_theme()
Register a module’s (or theme’s) theme implementations.
hook_theme_registry_alter()
Alter the theme registry information returned from hook_theme().
hook_translated_menu_link_alter()
Alter a menu link after it’s translated, but before it’s rendered.
hook_uninstall()
Remove any tables or variables that the module sets.
hook_update($node)
Respond to node updating.
hook_update_index
Update Drupal’s full-text index for this module.
hook_update_N
Perform a single update. For each patch which requires a database change add a new hook_update_N() whichwill be called by update.php.
hook_user($op,&$edit,&$account, $category= ULL)
Act on user account actions.
hook_user_operations()
Add mass user operations.
hook_validate($node)
Verify a node editing form.
hook_view($node, $teaser=FALSE, $page=FALSE)
Display a node.
hook_watchdog($log_msg)
Log an event message.
hook_xmlrpc
Register XML-RPC callbacks.
module_hook
Determine whether a module implements a hook.
module_implements
Determine which modules are implementing a hook.
module_invoke
Invoke a hook in a particular module.
module_invoke_all
Invoke a hook in all enabled modules that implement it.