? gmap_invoke_cleanup_1.patch
Index: gmap.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/gmap/gmap.module,v
retrieving revision 1.104.2.4
diff -u -p -r1.104.2.4 gmap.module
--- gmap.module	24 Jan 2010 04:17:30 -0000	1.104.2.4
+++ gmap.module	24 Feb 2010 10:55:45 -0000
@@ -43,7 +43,7 @@ function gmap_defaults() {
   );
   $defaults['behavior'] = array();
   $m = array();
-  $behaviors = module_invoke_all('gmap', 'behaviors', $m);
+  $behaviors = gmap_module_invoke('behaviors', $m);
   foreach ($behaviors as $k => $v) {
     $defaults['behavior'][$k] = $v['default'];
   }
@@ -70,6 +70,26 @@ function gmap_theme() {
 }
 
 /**
+ * Invokes hook_gmap() in every module.
+ *
+ * We can't use module_invoke_all() because we pass $map by reference.
+ */
+function gmap_module_invoke($op, &$map) {
+  foreach (module_implements('gmap') as $module) {
+    $function = $module . '_gmap';
+    $return = array();
+    $result = $function($op, $map);
+    if (isset($result) && is_array($result)) {
+      $return = array_merge_recursive($return, $result);
+    }
+    elseif (isset($result)) {
+      $return[] = $result;
+    }
+  }
+  return $return;
+}
+
+/**
  * Implementation of hook_gmap().
  */
 function gmap_gmap($op, &$map) {
@@ -912,10 +932,7 @@ function theme_gmap($element) {
   // @@@ Bdragon sez: Yeah, would be nice, but hard to guarantee functionality. Not everyone uses the static markerloader.
   $o = '<div style="' . implode('; ', $style) . ';" id="' . $element['#id'] . '"' . drupal_attributes($element['#attributes']) . '>' . t('Javascript is required to view this map.') . '</div>';
 
-  // $map can be manipulated by reference.
-  foreach (module_implements('gmap') as $module) {
-    call_user_func_array($module . '_gmap', array('pre_theme_map', &$map));
-  }
+  gmap_module_invoke('pre_theme_map', $map);
 
   if (isset($mapids[$element['#map']])) {
     drupal_set_message(t('Duplicate map detected! GMap does not support multiplexing maps onto one MapID! GMap MapID: %mapid', array('%mapid' => $element['#map'])), 'error');
Index: gmap_macro_builder.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/gmap/gmap_macro_builder.module,v
retrieving revision 1.6
diff -u -p -r1.6 gmap_macro_builder.module
--- gmap_macro_builder.module	24 Nov 2008 17:49:55 -0000	1.6
+++ gmap_macro_builder.module	24 Feb 2010 10:55:46 -0000
@@ -85,9 +85,7 @@ function gmap_macro_builder_form(&$form_
   // @@@ TODO: Roll this next section into an element, it's duplicated from the settings ui.
   $baselayers = array();
 
-  foreach (module_implements('gmap') as $module) {
-    call_user_func_array($module .'_gmap', array('baselayers', &$baselayers));
-  }
+  gmap_module_invoke('baselayers', $baselayers);
 
   $options = array();
   foreach ($baselayers as $name => $layers) {
Index: gmap_parse_macro.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/gmap/gmap_parse_macro.inc,v
retrieving revision 1.2
diff -u -p -r1.2 gmap_parse_macro.inc
--- gmap_parse_macro.inc	6 Apr 2009 21:32:46 -0000	1.2
+++ gmap_parse_macro.inc	24 Feb 2010 10:55:46 -0000
@@ -61,7 +61,7 @@ function _gmap_str2coord($str) {
 function _gmap_parse_macro($instring, $ver = 2) {
   // Get a list of keys that are "multiple."
   $m = array();
-  $multiple = module_invoke_all('gmap', 'macro_multiple', $m);
+  $multiple = gmap_module_invoke('macro_multiple', $m);
 
   // Remove leading and trailing tags
   if (substr(trim($instring), -1)==']') {
@@ -347,6 +347,12 @@ function _gmap_parse_macro($instring, $v
   }
 
   // The macro can now be manipulated by reference.
+  // Note: We do NOT use gmap_module_invoke here,
+  // as this $op has weird semantics for backwards
+  // compatibility / convenience reasons.
+  // (Specifically, modules are allowed to do arbitrary
+  // manipulations on $m OR return the changes
+  // they want to apply to $m.)
   foreach (module_implements('gmap') as $module) {
     $additions = call_user_func_array($module .'_gmap', array('parse_macro', &$m));
     if (!empty($additions)) {
Index: gmap_settings_ui.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/gmap/gmap_settings_ui.inc,v
retrieving revision 1.12.2.2
diff -u -p -r1.12.2.2 gmap_settings_ui.inc
--- gmap_settings_ui.inc	24 Jan 2010 04:17:30 -0000	1.12.2.2
+++ gmap_settings_ui.inc	24 Feb 2010 10:55:48 -0000
@@ -79,7 +79,7 @@ function gmap_admin_settings(&$form_stat
 
   // Allow previewable behaviors to affect the preview map.
   $m = array();
-  $behaviors = module_invoke_all('gmap', 'behaviors', $m);
+  $behaviors = gmap_module_invoke('behaviors', $m);
   foreach ($behaviors as $k => $v) {
     if (isset($v['previewable']) && $v['previewable']) {
       $form['gmap_default']['map']['#settings']['behavior'][$k] = $defaults['behavior'][$k];
@@ -172,9 +172,7 @@ function gmap_admin_settings(&$form_stat
 
   $baselayers = array();
 
-  foreach (module_implements('gmap') as $module) {
-    call_user_func_array($module .'_gmap', array('baselayers', &$baselayers));
-  }
+  gmap_module_invoke('baselayers', $baselayers);
 
   $options = array();
   foreach ($baselayers as $name => $layers) {
@@ -219,7 +217,7 @@ function gmap_admin_settings(&$form_stat
     '#description' => t('Behavior flags modify how a map behaves. Grayed out flags are not settable here, but may be set on a map by map basis via code or a macro. Changes to behaviors will not affect the preview map shown above until changes are saved.'),
   );
   $m = array();
-  $behaviors = module_invoke_all('gmap', 'behaviors', $m);
+  $behaviors = gmap_module_invoke('behaviors', $m);
   foreach ($behaviors as $k => $v) {
     $form['gmap_default']['behavior'][$k] = array(
       '#type' => 'checkbox',
