summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--contrib/location_cck/location_cck.module21
-rw-r--r--location.module37
2 files changed, 25 insertions, 33 deletions
diff --git a/contrib/location_cck/location_cck.module b/contrib/location_cck/location_cck.module
index 1733b4a..b6476bb 100644
--- a/contrib/location_cck/location_cck.module
+++ b/contrib/location_cck/location_cck.module
@@ -265,7 +265,6 @@ function location_cck_widget(&$form, &$form_state, $field, $items, $delta = 0) {
'#required' => $field['required'],
'#location_settings' => $settings,
'#default_value' => $location,
- '#element_validate' => array('location_cck_validate'),
);
// This is used to determine whether we are in a preview or not, because
// several pieces of code work differently when previewing.
@@ -278,26 +277,6 @@ function location_cck_widget(&$form, &$form_state, $field, $items, $delta = 0) {
}
/**
- * Add validation when a location is chosen on a map
- * but is given no name to warn it will not be
- * saved (won't make it through location_is_empty()).
- */
-function location_cck_validate($element, &$form_state) {
- $location = $element['#value'];
- $fields = $location;
- if (location_is_empty($location, $fields)) {
- if (!empty($location['locpick']['user_latitude']) && !empty($location['locpick']['user_longitude'])) {
- // We don't exactly which location fields are available
- // so just pick the first one for our error message.
- $field_key = array_shift(array_keys($fields));
- $labels = location_locationapi($fields, 'fields');
- $error_field = implode('][', $element['#parents']) .']['. $field_key;
- form_set_error($error_field, t('Location coordinates will not be stored unless they have %field_key or some other value set.', array('%field_key' => $labels[$field_key])));
- }
- }
-}
-
-/**
* CCK Emptiness check.
*/
function location_cck_content_is_empty($item, $field) {
diff --git a/location.module b/location.module
index d230d1f..b243ae5 100644
--- a/location.module
+++ b/location.module
@@ -1000,6 +1000,26 @@ function location_invoke_locationapi(&$location, $op, $a3 = NULL, $a4 = NULL, $a
}
/**
+ * Apply locpick twiddling to a location.
+ * This is needed before saving and comparison.
+ */
+function _location_patch_locpick(&$location) {
+ $inhibit_geocode = FALSE;
+ if (!empty($location['locpick'])) {
+ $location['locpick']['user_latitude'] = trim($location['locpick']['user_latitude']);
+ $location['locpick']['user_longitude'] = trim($location['locpick']['user_longitude']);
+ }
+ // If the user location was set, convert it into lat / lon.
+ if (!empty($location['locpick']['user_latitude']) && !empty($location['locpick']['user_longitude'])) {
+ $location['source'] = LOCATION_LATLON_USER_SUBMITTED;
+ $location['latitude'] = $location['locpick']['user_latitude'];
+ $location['longitude'] = $location['locpick']['user_longitude'];
+ $inhibit_geocode = TRUE;
+ }
+ return $inhibit_geocode;
+}
+
+/**
* Save a location.
*
* This is the central function for saving a location.
@@ -1038,18 +1058,7 @@ function location_save(&$location, $cow = TRUE, $criteria = array()) {
if (isset($location['lid']) && !empty($location['lid'])) {
$oldloc = (array)location_load_location($location['lid']);
}
-
- // @@@ This isn't the best place to do this...
- // But if the user only changes user lat/lon, we need to be able to detect it!
- if (!empty($location['locpick'])) {
- $location['locpick']['user_latitude'] = trim($location['locpick']['user_latitude']);
- $location['locpick']['user_longitude'] = trim($location['locpick']['user_longitude']);
- }
- // If the user location was set, convert it into lat / lon.
- if (!empty($location['locpick']['user_latitude']) && !empty($location['locpick']['user_longitude'])) {
- $location['source'] = LOCATION_LATLON_USER_SUBMITTED;
- $location['latitude'] = $location['locpick']['user_latitude'];
- $location['longitude'] = $location['locpick']['user_longitude'];
+ if (_location_patch_locpick($location)) {
$inhibit_geocode = TRUE;
}
@@ -1188,6 +1197,10 @@ function location_is_empty($location, &$filled) {
return TRUE;
}
+ // Patch locpick at this point.
+ // Otherwise, changing locpick only will not show a difference.
+ _location_patch_locpick($location);
+
$settings = isset($location['location_settings']) ? $location['location_settings'] : array();
$emptyloc = location_empty_location($settings);