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

  1. myhook.module: An empty module creating myhook namespace for custom hooks.
  2. 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.

Project information

Releases