MyHook
Categories
Component ID
890476
Component name
MyHook
Component type
module
Maintenance status
Development status
Component security advisory coverage
covered
Downloads
3219
Component created
Component changed
Component body
MyHook allows module developers to define on-the-fly custom hooks. It is like having a custom module working instantly without creating/installing module files.
The package includes
- myhook.module: An empty module creating myhook namespace for custom hooks.
- myhookadmin.module: Provides an administrator interface(admin/settings/myhook) allowing the developer define custom hooks for myhook.module.
Example hook_nodeapi() implementation that notifys admin by email of new content
function myhook_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
switch ($op) {
case 'insert':
drupal_mail_send(array(
'to' => 'admin@example.com',
'subject' => 'New content',
'body' => 'New content entered at ' . url('node/' . $node->nid, array('absolute' => TRUE)),
'headers' => array('From' => variable_get('site_mail', ini_get('sendmail_from'))),
));
break;
}
}
Differences from hooker module
Hooker allows to define functions only and you can not define the hooks/functions that hooker already implemented. e.g. hook_menu(), hook_theme(), hook_init(). It executes a separate eval process for each function defined.
OTH, MyHook allows you to write any code as if you are writing your own myhook.module. It provides a new namespace and allows to define all hooks.
It also allows you to keep the custom code in a file, which saves a DB hit and an eval process.
