You are here

function google_map_field_field_widget_form in Google Map Field 7

Same name and namespace in other branches
  1. 7.2 google_map_field.module \google_map_field_field_widget_form()

Implements hook_field_widget_form().

File

./google_map_field.module, line 195
This file defines all the necessary hooks and functions to create a Google Map Field field type and also a WYSIWYG editor plugin for inserting maps directly into filtered content.

Code

function google_map_field_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
  $fname = str_replace('_', '-', $element['#field_name']);
  $element['#title'] = t('Google Map Field Settings');
  $element['#description'] = '<p>' . t('To set a location for the map, use the controls to zoom in or out and drag the map to find the correct area. Once you have found the correct location click that point to set the map.') . '</p>';
  $element += array(
    '#type' => 'fieldset',
    '#tree' => TRUE,
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#after_build' => array(
      'google_map_field_after_build',
    ),
    '#fname' => $fname,
  );
  $element['fname'] = array(
    '#type' => 'hidden',
    '#value' => $fname,
  );
  $element['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Map Name'),
    '#default_value' => isset($items[$delta]['name']) ? $items[$delta]['name'] : NULL,
    '#prefix' => '<div class="clearfix"><div class="google_map_field_left30pc">',
  );
  $element['lat'] = array(
    '#type' => 'textfield',
    '#title' => t('Latitude'),
    '#required' => $instance['required'],
    '#element_validate' => array(
      'google_map_field_latlon_validate',
    ),
    '#default_value' => isset($items[$delta]['lat']) ? $items[$delta]['lat'] : NULL,
  );
  $element['lon'] = array(
    '#type' => 'textfield',
    '#title' => t('Longitude'),
    '#required' => $instance['required'],
    '#element_validate' => array(
      'google_map_field_latlon_validate',
    ),
    '#default_value' => isset($items[$delta]['lon']) ? $items[$delta]['lon'] : NULL,
  );
  $element['zoom'] = array(
    '#type' => 'textfield',
    '#title' => t('Zoom'),
    '#default_value' => isset($items[$delta]['zoom']) ? $items[$delta]['zoom'] : 9,
    '#attributes' => array(
      'readonly' => 'readonly',
    ),
  );
  $element['center_on'] = array(
    '#type' => 'textfield',
    '#title' => t('Center On'),
    '#description' => t('To center the map on an approximate location, enter the location in the box above, e.g. "London, UK" or "1 Southwark Street, London, UK" and click \'center\''),
  );
  $element['do_center'] = array(
    '#type' => 'button',
    '#value' => t('center'),
    '#attributes' => array(
      'onclick' => 'return google_map_field_doCenter();',
    ),
    '#suffix' => '</div>',
  );
  $element['map'] = array(
    '#markup' => theme('google_map_field_map_picker'),
    '#prefix' => '<div class="google_map_field_left65pc">',
    '#suffix' => '</div></div>',
  );
  return $element;
}