You are here

function theme_getlocations_fields_field_widget_form in Get Locations 7

Same name and namespace in other branches
  1. 7.2 modules/getlocations_fields/getlocations_fields.module \theme_getlocations_fields_field_widget_form()

The input form

Parameters

array $variables:

Return value

Returns $output

File

modules/getlocations_fields/getlocations_fields.module, line 4652
getlocations_fields.module @author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL

Code

function theme_getlocations_fields_field_widget_form($variables) {
  $form = $variables['form'];
  $output = '';
  $settings = $form['settings']['#value'];
  unset($form['settings']);
  $active = $form['active']['#value'];
  list($map, $mapid) = getlocations_fields_getmap($settings, $active);

  // attributes
  $fieldlist = array(
    'name',
    'street',
    'additional',
    'city',
    'province',
    'postal_code',
    'country',
    'latitude',
    'longitude',
    'mapzoom',
    'sv_heading',
    'sv_zoom',
    'sv_pitch',
    'map_maptype',
    'sv_enable',
    'sv_showfirst',
  );
  foreach ($fieldlist as $field) {
    if (isset($form[$field])) {
      $form[$field]['#attributes'] = array(
        'class' => array(
          'getlocations_' . $field . '_' . $mapid,
        ),
      );
    }
  }
  if (isset($form['address'])) {
    $form['address']['#attributes'] = array(
      'id' => $active ? 'getlocations_address_' . $mapid : 'getlocations_default_address',
      'placeholder' => t('Enter an address'),
    );
  }
  if ($mapid !== NULL && isset($form['geobutton'])) {
    $geobutton = '<p><input type="button" value="' . t('Geocode this address') . '" title="' . t('Get the latitude and longitude for this address') . '" id="getlocations_geocodebutton_' . $mapid . '" class="form-submit" /></p>';
    $form['geobutton']['#markup'] = $geobutton;
  }
  if ($mapid !== NULL && isset($form['smart_ip_button']) && module_exists('smart_ip')) {
    $smart_ip_button = '<p><input type="button" value="' . t('Use current user position') . '" title="' . t('Get the latitude and longitude for this address from the user IP') . '" id="getlocations_smart_ip_button_' . $mapid . '" class="form-submit" /></p>';
    $form['smart_ip_button']['#markup'] = $smart_ip_button;
  }

  // html5 and google
  if (getlocations_is_mobile() && $mapid !== NULL && isset($form['geolocation_button'])) {
    $geolocation_button = '<p><input type="button" value="' . t('Find Location') . '" title="' . t('Get the latitude and longitude for this address from the browser') . '" id="getlocations_geolocation_button_' . $mapid . '" class="form-submit" />&nbsp;<span id="getlocations_geolocation_status_' . $mapid . '" ></span></p>';
    $geolocation_button .= '<p>Use the browser to find your current location</p>';
    $form['geolocation_button']['#markup'] = $geolocation_button;
  }

  // Clear button
  if (isset($form['clear_button'])) {
    $clear_button = '<p><input type="button" value="' . t('Clear') . '" title="' . t('Clear the address on the form') . '" id="getlocations_clear_button_' . $mapid . '" class="form-submit" /></p>';
    $form['clear_button']['#markup'] = $clear_button;
  }
  $form['latitude']['#prefix'] = '<div class="getlocations_fields_latlon_wrapper clearfix"><div class="getlocations_fields_lat_wrapper">';
  $form['latitude']['#suffix'] = '</div>';
  $form['longitude']['#prefix'] = '<div class="getlocations_fields_lon_wrapper">';
  $form['longitude']['#suffix'] = '</div></div>';
  if (isset($form['marker']) && $form['marker']['#type'] != 'value') {

    // colorbox marker
    $link = getlocations_markerpicker_link($form['marker']['#id'], 'i');
    $form['marker']['#field_suffix'] = '&nbsp;' . $link;
    $form['marker']['#prefix'] = '<div class="getlocations_fields_marker_wrapper">';
    $form['marker']['#suffix'] = '</div>';
  }
  $form['city']['#prefix'] = '<div class="getlocations_fields_city_wrapper">';
  $form['city']['#suffix'] = '</div>';
  $form['province']['#prefix'] = '<div class="getlocations_fields_province_wrapper">';
  $form['province']['#suffix'] = '</div>';
  $form['country']['#prefix'] = '<div class="getlocations_fields_country_wrapper">';
  if (isset($form['country_display'])) {
    $form['country_display']['#suffix'] = '</div>';
  }
  else {
    $form['country']['#suffix'] = '</div>';
  }
  $msg = t('To use the map to find a location, drag the marker or click on the map.');
  if (isset($settings['map_settings_allow'])) {
    $map_settings_allow = $settings['map_settings_allow'];
  }
  else {
    $map_settings_allow = getlocations_fields_map_settings_allow();
  }
  if ($map_settings_allow) {
    $msg .= '<br />' . t('You can also set the map type and zoom');
  }
  if (!$active) {
    $msg = t('A preview of the current map settings.') . '<br />' . t('You can adjust the Map center, Zoom and map type by changing the map.') . '<br />' . t('For all other changes use the form. Remember to Save when you are done.');
  }
  $form['map']['#prefix'] = '<div class="getlocations_fields_map_wrapper">';
  $form['map']['#suffix'] = '</div>';
  if ($settings['use_address'] < 1) {
    $form['map']['#markup'] = '<p>' . t('If you leave the address empty you can Geocode by moving the marker on the map') . '</p>';
  }
  else {
    $form['map']['#markup'] = '';
  }
  $form['map']['#markup'] .= '<p>' . $msg . '</p><div class="getlocations_fields_map">' . $map . '</div>';
  if (isset($settings['streetview_settings_allow'])) {
    $streetview_settings_allow = $settings['streetview_settings_allow'];
  }
  else {
    $streetview_settings_allow = getlocations_fields_streetview_settings_allow();
  }
  if ($active && $streetview_settings_allow) {
    $form['map']['#markup'] .= '<div id="getlocations_streetview_setup_' . $mapid . '">';
    $form['map']['#markup'] .= '<input type="button" value="' . t('Streetview Setup') . '" title="' . t('Configure streetview heading, zoom and pitch for this map.') . '" id="getlocations_streetview_setupbutton_' . $mapid . '" class="form-submit" />';
    $form['map']['#markup'] .= '</div>';
  }

  // wrap 'fake' required in a div
  if ($mapid !== NULL && isset($form['getlocations_required'])) {
    $requireds = explode(',', $form['getlocations_required']['#value']);
    foreach ($requireds as $id) {
      $form[$id]['#prefix'] = '<div class="getlocations_required_' . $id . '_' . $mapid . '">';
      $form[$id]['#suffix'] = '</div>';
    }
    unset($form['getlocations_required']);
  }
  $output .= drupal_render_children($form);
  return $output;
}