Skip to content
Snippets Groups Projects
Commit a4f5d5e9 authored by Brandon Bergren's avatar Brandon Bergren
Browse files

Fix #582934, patch by me, rerolled by pivica and hutch: PHP 5.3 compatibility...

Fix #582934, patch by me, rerolled by pivica and hutch: PHP 5.3 compatibility for hook_gmap(). (Manual backport)
parent e6e0edd7
No related branches found
No related tags found
No related merge requests found
...@@ -44,7 +44,7 @@ function gmap_defaults() { ...@@ -44,7 +44,7 @@ function gmap_defaults() {
); );
$defaults['behavior'] = array(); $defaults['behavior'] = array();
$m = array(); $m = array();
$behaviors = module_invoke_all('gmap', 'behaviors', $m); $behaviors = gmap_module_invoke('behaviors', $m);
foreach ($behaviors as $k => $v) { foreach ($behaviors as $k => $v) {
$defaults['behavior'][$k] = $v['default']; $defaults['behavior'][$k] = $v['default'];
} }
...@@ -70,6 +70,26 @@ function gmap_theme() { ...@@ -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(). * Implementation of hook_gmap().
*/ */
...@@ -927,10 +947,7 @@ function theme_gmap($element) { ...@@ -927,10 +947,7 @@ function theme_gmap($element) {
// @@@ Bdragon sez: Yeah, would be nice, but hard to guarantee functionality. Not everyone uses the static markerloader. // @@@ 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>'; $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. gmap_module_invoke('pre_theme_map', $map);
foreach (module_implements('gmap') as $module) {
call_user_func_array($module . '_gmap', array('pre_theme_map', &$map));
}
if (isset($mapids[$element['#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'); drupal_set_message(t('Duplicate map detected! GMap does not support multiplexing maps onto one MapID! GMap MapID: %mapid', array('%mapid' => $element['#map'])), 'error');
......
...@@ -85,9 +85,7 @@ function gmap_macro_builder_form(&$form_state, $settings = array(), $hide = arra ...@@ -85,9 +85,7 @@ function gmap_macro_builder_form(&$form_state, $settings = array(), $hide = arra
// @@@ TODO: Roll this next section into an element, it's duplicated from the settings ui. // @@@ TODO: Roll this next section into an element, it's duplicated from the settings ui.
$baselayers = array(); $baselayers = array();
foreach (module_implements('gmap') as $module) { gmap_module_invoke('baselayers', $baselayers);
call_user_func_array($module .'_gmap', array('baselayers', &$baselayers));
}
$options = array(); $options = array();
foreach ($baselayers as $name => $layers) { foreach ($baselayers as $name => $layers) {
......
...@@ -61,7 +61,7 @@ function _gmap_str2coord($str) { ...@@ -61,7 +61,7 @@ function _gmap_str2coord($str) {
function _gmap_parse_macro($instring, $ver = 2) { function _gmap_parse_macro($instring, $ver = 2) {
// Get a list of keys that are "multiple." // Get a list of keys that are "multiple."
$m = array(); $m = array();
$multiple = module_invoke_all('gmap', 'macro_multiple', $m); $multiple = gmap_module_invoke('macro_multiple', $m);
// Remove leading and trailing tags // Remove leading and trailing tags
if (substr(trim($instring), -1)==']') { if (substr(trim($instring), -1)==']') {
...@@ -347,6 +347,12 @@ function _gmap_parse_macro($instring, $ver = 2) { ...@@ -347,6 +347,12 @@ function _gmap_parse_macro($instring, $ver = 2) {
} }
// The macro can now be manipulated by reference. // 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) { foreach (module_implements('gmap') as $module) {
$additions = call_user_func_array($module .'_gmap', array('parse_macro', &$m)); $additions = call_user_func_array($module .'_gmap', array('parse_macro', &$m));
if (!empty($additions)) { if (!empty($additions)) {
......
...@@ -79,7 +79,7 @@ function gmap_admin_settings(&$form_state) { ...@@ -79,7 +79,7 @@ function gmap_admin_settings(&$form_state) {
// Allow previewable behaviors to affect the preview map. // Allow previewable behaviors to affect the preview map.
$m = array(); $m = array();
$behaviors = module_invoke_all('gmap', 'behaviors', $m); $behaviors = gmap_module_invoke('behaviors', $m);
foreach ($behaviors as $k => $v) { foreach ($behaviors as $k => $v) {
if (isset($v['previewable']) && $v['previewable']) { if (isset($v['previewable']) && $v['previewable']) {
$form['gmap_default']['map']['#settings']['behavior'][$k] = $defaults['behavior'][$k]; $form['gmap_default']['map']['#settings']['behavior'][$k] = $defaults['behavior'][$k];
...@@ -181,9 +181,7 @@ function gmap_admin_settings(&$form_state) { ...@@ -181,9 +181,7 @@ function gmap_admin_settings(&$form_state) {
$baselayers = array(); $baselayers = array();
foreach (module_implements('gmap') as $module) { gmap_module_invoke('baselayers', $baselayers);
call_user_func_array($module .'_gmap', array('baselayers', &$baselayers));
}
$options = array(); $options = array();
foreach ($baselayers as $name => $layers) { foreach ($baselayers as $name => $layers) {
...@@ -228,7 +226,7 @@ function gmap_admin_settings(&$form_state) { ...@@ -228,7 +226,7 @@ function gmap_admin_settings(&$form_state) {
'#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.'), '#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(); $m = array();
$behaviors = module_invoke_all('gmap', 'behaviors', $m); $behaviors = gmap_module_invoke('behaviors', $m);
foreach ($behaviors as $k => $v) { foreach ($behaviors as $k => $v) {
$form['gmap_default']['behavior'][$k] = array( $form['gmap_default']['behavior'][$k] = array(
'#type' => 'checkbox', '#type' => 'checkbox',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment