Friday, February 11, 2011

Drupal - Module hooks invoke procedure


How does all the hooks inside all the modules (custom & contributed) gets invoked and executed,

module_implements() - this is the function which Determine which modules are implementing a hook.

function module_implements($hook, $sort = FALSE, $refresh = FALSE) {
  static $implementations;

  if ($refresh) {
    $implementations = array();
    return;
  }

  if (!isset($implementations[$hook])) {
    $implementations[$hook] = array();
    $list = module_list(FALSE, TRUE, $sort);
    foreach ($list as $module) {
      if (module_hook($module, $hook)) {
        $implementations[$hook][] = $module;
      }
    }
  }


In this function it will call the module_list() function which returns all the enabled modules, further on which module_hook() function is called which checks whether the module uses that hook function

function module_hook($module, $hook) {
  return function_exists($module .'_'. $hook);
}

No comments:

Post a Comment

Customizing the Search form - Drupal

To change the label text and text inside the search box and the text on the submit and changing the Submit button image, you can use the fo...