Skip to content
Snippets Groups Projects
Commit 4b01024a authored by Volodymyr Baldych's avatar Volodymyr Baldych Committed by Taras Kruts
Browse files

Issue #3394300: Fix location filter on admin/people page

parent d0d1c264
No related branches found
No related tags found
No related merge requests found
social_geolocation.location:
js:
assets/js/social_geolocation_autocomplete.js: {}
assets/js/social_geolocation_autocomplete.js: {}
\ No newline at end of file
......@@ -56,8 +56,11 @@ function social_geolocation_form_views_exposed_form_alter(&$form, FormStateInter
social_geolocation_attach_views_location_filter($form, 'fieldset');
// Clean up profile geolocation field filters added by default.
$form['field_profile_geolocation_proximity']['#type'] = 'hidden';
// Hide fields that shouldn't be shown.
hide($form['field_profile_geolocation_proximity_center']);
hide($form['field_profile_geolocation_proximity']);
// Clean up profile geolocation filter fields added by default.
unset($form['center']);
// It's possible that location_details wasn't created because there is no
......@@ -65,11 +68,7 @@ function social_geolocation_form_views_exposed_form_alter(&$form, FormStateInter
// we don't tweak the fieldset.
if (isset($form['location_details'])) {
$form['location_details']['geolocation_geocoder_address']['#size'] = 30;
unset(
$form['location_details']['proximity']['#description'],
$form['location_details']['geolocation_geocoder_address']['#description']
);
unset($form['location_details']['geolocation_geocoder_address']['#description']);
}
}
......@@ -89,22 +88,25 @@ function social_geolocation_attach_views_location_filter(array &$form, string $c
return;
}
$range_min = 10;
$range_max = 1000;
$unit_of_measurement = \Drupal::config('social_geolocation.settings')->get('unit_of_measurement');
$form['#validate'][] = '_social_geolocation_form_views_exposed_form_validate';
// Set up a container for our location filtering fields.
$form['location_details'] = [
'#title' => t('Location range'),
'#title' => t('Location & Range'),
'#type' => $container_type,
'#weight' => 50,
];
$form['location_details']['proximity'] = [
'#type' => 'number',
'#title' => t('Distance (@unitOfMeasurement)', ['@unitOfMeasurement' => $unit_of_measurement]),
'#description' => t('Recommended range from 10 to 1000.'),
'#min' => 0,
'#max' => 10000,
'#title' => t('Range'),
'#description' => t("From {$range_min} to {$range_max} {$unit_of_measurement}"),
'#min' => $range_min,
'#max' => $range_max,
'#weight' => 10,
];
......@@ -144,20 +146,24 @@ function _social_geolocation_form_views_exposed_form_validate(&$form, FormStateI
$address_geocoded = _social_geolocation_geocode_address($address);
if (!empty($address_geocoded)) {
// Set values for proximity.
// Default is 20.
// Set values for field_profile_geolocation_proximity. Default is 20.
$proximity = $form_state->getValue('proximity');
if (!empty($form_state->getValue('proximity'))) {
$form_state->setValue(['field_profile_geolocation_proximity'], $proximity);
$form_state->setValue('field_profile_geolocation_proximity', $proximity);
}
$form_state->setValue(
['lat'], $address_geocoded['lat']
);
$form_state->setValue([
'field_profile_geolocation_proximity_center',
'coordinates',
'lat',
], $address_geocoded['lat']);
$form_state->setValue(
['lng'], $address_geocoded['lng']
);
$form_state->setValue([
'field_profile_geolocation_proximity_center',
'coordinates',
'lng',
],
$address_geocoded['lng']);
}
else {
$element = ['geolocation_geocoder_address'];
......@@ -420,4 +426,4 @@ function _social_geolocation_reformat_address_for_api(AddressInterface $address)
}
return [];
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment