You are here

function geolocation_field_widget_form in Geolocation Field 7

Implements hook_field_widget_form().

File

./geolocation.module, line 254
A geolocation field using the Field API.

Code

function geolocation_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
  $lat_value = isset($items[$delta]['lat']) ? $items[$delta]['lat'] : '';
  $lng_value = isset($items[$delta]['lng']) ? $items[$delta]['lng'] : '';
  $element += array(
    '#delta' => $delta,
  );

  // Wrap in a fieldset for single fields.
  if ($field['cardinality'] == 1) {
    $element['#type'] = 'fieldset';
  }
  $element['lat'] = array();
  $element['lng'] = array();
  switch ($instance['widget']['type']) {
    case 'geolocation_text':
      $element['lat'] += array(
        '#title' => t('Latitude'),
        '#type' => 'textfield',
        '#default_value' => $lat_value,
        '#size' => 30,
        '#maxlength' => 30,
        '#required' => $instance['required'],
      );
      $element['lng'] += array(
        '#title' => t('Longitude'),
        '#type' => 'textfield',
        '#default_value' => $lng_value,
        '#size' => 30,
        '#maxlength' => 30,
        '#required' => $instance['required'],
      );
      $element['#attached']['css'][] = drupal_get_path('module', 'geolocation') . '/geolocation.css';
      break;
  }
  return $element;
}