Index: includes/module.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/module.inc,v
retrieving revision 1.82
diff -u -F^f -r1.82 module.inc
--- includes/module.inc 20 Aug 2006 05:57:40 -0000 1.82
+++ includes/module.inc 22 Aug 2006 00:08:52 -0000
@@ -193,6 +193,27 @@ function module_disable($module) {
}
/**
+ * Updates system hook definitions.
+ */
+function module_update_hooks($module, $enable = 1) {
+ $hooks = call_user_func("$module_define_hooks");
+ if ($enable) {
+ foreach ($hooks as $hook) {
+ $implementations = variable_get($hook, array());
+ $implementations[$module] = $module;
+ variable_set($hook, $implementations);
+ }
+ }
+ elseif ($disable) {
+ foreach ($hooks as $hook) {
+ $implementations = variable_get($hook, array());
+ unset($implementations[$module]);
+ variable_set($hook, $implementations);
+ }
+ }
+}
+
+/**
* @defgroup hooks Hooks
* @{
* Allow modules to interact with the Drupal core.
@@ -240,25 +261,11 @@ function module_hook($module, $hook) {
* An array with the names of the modules which are implementing this hook.
*/
function module_implements($hook, $sort = FALSE) {
- static $implementations;
-
- 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;
- }
- }
+ $modules = array_keys(variable_get("hook_$hook", array()));
+ if ($sort) {
+ sort($modules);
}
-
- // The explicit cast forces a copy to be made. This is needed because
- // $implementations[$hook] is only a reference to an element of
- // $implementations and if there are nested foreaches (due to nested node
- // API calls, for example), they would both manipulate the same array's
- // references, which causes some modules' hooks not to be called.
- // See also http://www.zend.com/zend/art/ref-count.php.
- return (array)$implementations[$hook];
+ return $modules;
}
/**