I have been looking through the Drupal code and have been trying to understand how it ticks. I understand the way that the hooks works, but do not understand where the base definitions are kept. I have been going through each of the files in my Drupal installation and do not see a definition of each of the hooks, except for init and exit. Where is this kept? How is it restricting which hooks are implementable?

Comments

tormu’s picture

sukh.singh’s picture

I knew the link for the hook api but what i want is in drupal where these hooks are defined so that i can know what these are doing rather then checking it online.

naveenpl’s picture

I think you are looking for this.

/**
 * Determine whether a module implements a hook.
 *
 * @param $module
 *   The name of the module (without the .module extension).
 * @param $hook
 *   The name of the hook (e.g. "help" or "menu").
 * @return
 *   TRUE if the module is both installed and enabled, and the hook is
 *   implemented in that module.
 */
function module_hook($module, $hook) {
  return function_exists($module .'_'. $hook);
}

Check the common/module.inc for more details.
Different core hooks are
http://api.drupal.org/api/group/hooks/5

Hope this will help
Cheers.

sukh.singh’s picture

The things u told me are good but what i want is to see where these hook are declared in drupal that is what i want.

naveenpl’s picture

Did you mean this

/**
 * Implementation of hook_help().
 */
function modulename_help($section) {
// help content
}

/**
 * Implementation of hook_menu().
 */
function modulename_menu($may_cache) {
// menu list
}
/**
 * Implementation of hook_perm().
 */
function modulename_perm() {
  return array('administer', users');
}

These are declared in the modulename.module file of each modules.
For reference check user, comment and node (core) modules.

Hope this will help
Cheers.

tormu’s picture

http://api.drupal.org/api/group/hooks/5 -> You see the list of different hooks and the column "Location" tells the file where that hook is declared.