Obviously there is a learning curve to overcome in order to understand a concept of a world of a Drupal's hook system, that is, a.k.a callbacks. The following is a summary of hooks both for a management system and a form system, which I organized.
Hooks for a Management
The implementation of hook_help is also recommended even though those are described in yourmodule.info since Drupal 5.x
A set of three hooks such as hook_perm, hook_access and hook_menu should be always implemented together. It must be implemented in order to set access controls in every single user group at Home > Administer > Access Control
Describes which access privilege is bound to the corresponding operation, which is an argument of this function, such as $op == 'create'、$op == 'update'、$op == 'delete', and etc.
Maps a set of the path, module, privilege and page tile in this hook.
'type' => MENU_NORMAL_ITEM enables the item to show in the menu system
'type' => MENU_CALLBACK disables the item to show in the menu system and only to call the mapped function with the path.
The following description enables two forms in one module. The significant lines are 'module' => 'form1' and 'module' => 'form1'; eventually they turn out the function name such as form1_view, form2_view which are used as the prefix such as form1_ or form2_ with hooks for forms on the later explanation.
<?php
function hook_node_info() {
return array(
'form1' => array(
'name' => t('form1'),
'module' => 'form1',
'description' => t("Describe the explanation of form1"),
),
'form2' => array(
'name' => t('form2'),
'module' => 'form2',
'description' => t("Describe the explanation of form2"),
)
);
}
?>
Enables the configurable values in this module to setup under the menu such as Home > Administer > Site Configuration > Your Module Settings
Hooks for a Form
Renders a page or shows a form
Display a form to input data
Allows the inputted values to check when a submit button is pressed; you can make an error page show when the valus are invalid strings or out of the range by calling form_set_error('Write the field name of the item here', t('Write an error description here'));
Called before hook_insert is called when a submit button is pressed. And also allows $node that should be passed to hook_insert to alter
Receives values from an inputting form (that is, just a 'form') and stores a record (that is, a node) into the database. Virtually, An SQL statement 'INSERT' will be issued in this hook. As a result, a new node will be added into the database.
Receives values from an edit form (that is, just a 'form') and updates a record (that is, a node) in the database. Virtually, An SQL statement 'UPDATE' will be issued in this hook.
Called when a Delete button is pressed as the same as an edit form (that is, just a 'form'). A node stored in a database is deleted. Virtually, An SQL statement 'DELETE' will be issued in this hook.
In Drupal, each document created by a user is stored into 'node' table with a unit 'node'. If you add a custom field into 'node', you must explicitly specify your custom field and load the node when your module is about to show the node. The code is the following.
<?php
function hook_load($node) {
$r = db_fetch_object(
db_query('SELECT `your_id`, `your_field1`, `your_field2`, ... FROM {your_table_name} WHERE nid = %d', $node->nid)
);
return $r;
}
?>
Allows node vales to edit before calling hook_view. For example, if you show a date formatted to mm/dd/yyyy before calling hook_view, you can make the date format in this funciton.
Display a node. If you implement 'yourmodule_prepare', it should be called at the beginning of this hook implementation.
<?php
function hook_view(&$node, $teaser = FALSE, $page = FALSE) {
$node = node_prepare($node, $teaser);
yourmodule_prepare($node);
...
}
?>