Hey all. Great module as always. When trying to make a simple Geolocation behavior with options, I ran into the issue where I can define new behavior options (and these show up in the interface), but they are not available when rendering, or in the "pre_theme" op of the hook. I haven't had time to look into detail about this. here is my hook code.

function mappingdrupal_gmap_extensions_gmap($op, &$map) {
  switch ($op) {
    case 'pre_theme_map':
      // We should check of the behavior is enable, but it does not
      // seem to be availble here.
      drupal_add_js(drupal_get_path('module', 'mappingdrupal_gmap_extensions') . 
        '/mappingdrupal_gmap_extensions.js');
      break;
    
    case 'behaviors':
      // These options do show up in the interface, and are saved.
      return array(
        'geolocate_auto' => array(
          'title' => t('Geolocate user automatically'),
          'default' => FALSE,
          'help' => t('This will geolocate the user on each page load and focus the map there.'),
        ),
        'geolocate_block' => array(
          'title' => t('Geolocate user with block link'),
          'default' => FALSE,
          'help' => t('This will geolocate the user only if they use the action on the GMap Geolocate block.'),
        ),
      );
      break;
  }
}

Comments

axgalloway’s picture

Anyone made progress on this?

zhuber’s picture

I'm having issues with this as well. Upon further inspection, it looks like the the _gmap_pre_render_map function runs after hook_gmap.

This means that changes made during with a custom hook_gmap function do not actually get rendered out (at least not for me).

jaxxed’s picture

I'm not sure that I totally understand the problem but:

A. default behaviors for gmap form elements are collected (via gmaps_defaults()) in the gmap_element_info() declaration of the form elements that gmaps provides. You should see the default values (including behaviours) in #map_settings. This collection absolutely happens before the #pre_render.
B. default behaviours are again added in theme_gmap(), which makes it usefull for cases where you used the theme('gmap') method directly, bypassing the Drupal form API. In the theme function the module performs an array_merge() on the #gmap_settings with the gmap_defaults(), which means that if you removed the 'behavior' attribute, the default behaviors (uncached) are added again.

_gmap_pre_render_map does some modifications on the behaviours, I'm not sure what negative effect it will have. Likely something in form_alter could cause problems, or in a custom theme override of theme_gmap.

Can you clarify what is going wrong? You can see your custom behaviours in the UI?, but they don't get applied at the JS level?

P.S. Can you clarify that you are still using the 7.x-1.x branch, and not the 2.x branch?