You are here

location_gmap_find_address.module in GMap Module 7.2

The Location GMap Fnd Address module adds a special button to all location fields that use gmap.

File

location_gmap_find_address/location_gmap_find_address.module
View source
<?php

/**
 * @file
 * The Location GMap Fnd Address module adds a special button
 * to all location fields that use gmap.
 */

/**
 * Implements hook_field_widget_form_alter().
 */
function location_gmap_find_address_field_widget_form_alter(&$element, &$form_state, $context) {
  if ($context['field']['type'] == 'location' && variable_get('location_usegmap', 0)) {
    if (isset($element['#location_settings']['form']['fields']['locpick'])) {
      $js_path = drupal_get_path('module', 'location_gmap_find_address') . '/location_gmap_find_address.js';
      $element['#attached']['js'][$js_path] = array(
        'scope' => 'footer',
      );
      $element["#pre_render"] = array(
        'location_gmap_find_address_location_pre_render',
      );
    }
  }
}

/**
 * Callback for element #pre_render property.
 *
 * @param array $element
 *   Element that will be processed.
 *
 * @return array
 *   An element with prefix property.
 *
 * @see location_gmap_find_address_field_widget_form_alter()
 */
function location_gmap_find_address_location_pre_render($element) {
  $element['locpick']["#prefix"] = '<div class="form-item location-gmap-find-address-button-wrapper"><button type="button" class="location-gmap-find-address-button" value="' . $element['#id'] . '">' . t('Find Address on Map') . '</button></div>';
  return $element;
}