function geofield_field_widget_form in Geofield 7
Same name and namespace in other branches
- 7.2 geofield.widgets.inc \geofield_field_widget_form()
Implements hook_field_widget_form().
File
- ./
geofield.widgets.inc, line 102 - Provides field widget hooks for geofield module.
Code
function geofield_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $base) {
$widget = $instance['widget'];
$settings = $widget['settings'];
$element = geofield_get_base_element($base, $items, $delta);
if ($widget['type'] == 'geofield_wkt') {
$element['wkt']['#title'] = 'Well Known Text';
$element['wkt']['#type'] = 'textarea';
$element['master_column']['#value'] = 'wkt';
}
if ($widget['type'] == 'geofield_geojson') {
$element['wkt']['#title'] = 'GeoJSON';
$element['wkt']['#type'] = 'textarea';
// We're actually displaying as GeoJSON, not wkt. This is confusing.
geophp_load();
$default_value = '';
try {
$wkt = isset($items[$delta]['wkt']) ? $items[$delta]['wkt'] : NULL;
$geometry = geoPHP::load($wkt, 'wkt');
if ($geometry) {
$default_value = $geometry
->out('json');
}
} catch (Exception $e) {
// @TODO: Not sure if we should do validation here or not...
}
$element['wkt']['#default_value'] = $default_value;
$element['master_column']['#value'] = 'wkt';
$element['input_format']['#value'] = 'geojson';
}
if ($widget['type'] == 'geofield_latlon') {
$element['lat']['#title'] = 'Latitude';
$element['lat']['#type'] = 'textfield';
$element['lon']['#title'] = 'Longitude';
$element['lon']['#type'] = 'textfield';
$element['master_column']['#value'] = 'latlon';
}
if ($widget['type'] == 'geofield_bounds') {
$element['left']['#title'] = 'Left Longitude';
$element['left']['#type'] = 'textfield';
$element['top']['#title'] = 'Top Latitude';
$element['top']['#type'] = 'textfield';
$element['right']['#title'] = 'Right Longitude';
$element['right']['#type'] = 'textfield';
$element['bottom']['#title'] = 'Bottom Latitude';
$element['bottom']['#type'] = 'textfield';
$element['master_column']['#value'] = 'bounds';
}
if ($widget['type'] == 'geofield_textfields') {
$element['wkt']['#title'] = 'Well Known Text';
$element['wkt']['#type'] = 'textarea';
$element['geo_type']['#title'] = 'Geometry Type';
$element['geo_type']['#type'] = 'textfield';
$element['lat']['#title'] = 'Latitude';
$element['lat']['#type'] = 'textfield';
$element['lon']['#title'] = 'Longitude';
$element['lon']['#type'] = 'textfield';
$element['left']['#title'] = 'Left Longitude';
$element['left']['#type'] = 'textfield';
$element['top']['#title'] = 'Top Latitude';
$element['top']['#type'] = 'textfield';
$element['right']['#title'] = 'Right Longitude';
$element['right']['#type'] = 'textfield';
$element['bottom']['#title'] = 'Bottom Latitude';
$element['bottom']['#type'] = 'textfield';
}
if ($widget['type'] == 'geofield_geolocation') {
$element['#attached']['js'][] = drupal_get_path('module', 'geofield') . '/js/geolocation.js';
$element['lat']['#title'] = 'Latitude';
$element['lat']['#type'] = 'textfield';
$element['lon']['#title'] = 'Longitude';
$element['lon']['#type'] = 'textfield';
$element['master_column']['#value'] = 'latlon';
}
if ($widget['type'] == 'geofield_openlayers') {
$openlayers_map_id = !empty($instance['widget']['settings']['openlayers_map']) ? $instance['widget']['settings']['openlayers_map'] : 'geofield_widget_map';
$element['#openlayers_mapname'] = $openlayers_map_id;
$element['#after_build'] = array(
'geofield_widget_openlayers_afterbuild',
);
}
return $element;
}