public function ProximityFilter::buildExposeForm in Geolocation Field 8
Options form subform for exposed filter options.
Overrides NumericFilter::buildExposeForm
See also
buildOptionsForm()
File
- src/
Plugin/ views/ filter/ ProximityFilter.php, line 106
Class
- ProximityFilter
- Filter handler for search keywords.
Namespace
Drupal\geolocation\Plugin\views\filterCode
public function buildExposeForm(&$form, FormStateInterface $form_state) {
$geocoder_definitions = $this->geolocationCore
->getGeocoderManager()
->getLocationCapableGeocoders();
if ($geocoder_definitions) {
$form['expose']['input_by_geocoding_widget'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Use geocoding widget to retrieve location values'),
'#default_value' => $this->options['expose']['input_by_geocoding_widget'],
'#states' => [
'visible' => [
'select[name="options[proximity_source]"]' => [
'value' => 'exposed',
],
],
],
];
$geocoder_options = [];
foreach ($geocoder_definitions as $id => $definition) {
$geocoder_options[$id] = $definition['name'];
}
$form['expose']['geocoder_plugin_settings'] = [
'#type' => 'container',
'#states' => [
'visible' => [
'input[name="options[expose][input_by_geocoding_widget]"]' => [
'checked' => TRUE,
],
],
],
];
$geocoder_container =& $form['expose']['geocoder_plugin_settings'];
$geocoder_container['plugin_id'] = [
'#type' => 'select',
'#options' => $geocoder_options,
'#title' => $this
->t('Geocoder plugin'),
'#default_value' => $this->options['expose']['geocoder_plugin_settings']['plugin_id'],
'#ajax' => [
'callback' => [
get_class($this->geolocationCore
->getGeocoderManager()),
'addGeocoderSettingsFormAjax',
],
'wrapper' => 'geocoder-plugin-settings',
'effect' => 'fade',
],
];
if (!empty($this->options['expose']['geocoder_plugin_settings']['plugin_id'])) {
$geocoder_plugin = $this->geolocationCore
->getGeocoderManager()
->getGeocoder($this->options['expose']['geocoder_plugin_settings']['plugin_id'], $this->options['expose']['geocoder_plugin_settings']['settings']);
}
elseif (current(array_keys($geocoder_options))) {
$geocoder_plugin = $this->geolocationCore
->getGeocoderManager()
->getGeocoder(current(array_keys($geocoder_options)));
}
if (!empty($geocoder_plugin)) {
$geocoder_settings_form = $geocoder_plugin
->getOptionsForm();
if ($geocoder_settings_form) {
$geocoder_container['settings'] = $geocoder_settings_form;
}
}
if (empty($geocoder_container['settings'])) {
$geocoder_container['settings'] = [
'#type' => 'html_tag',
'#tag' => 'span',
'#value' => $this
->t("No settings available."),
];
}
$geocoder_container['settings'] = array_replace_recursive($geocoder_container['settings'], [
'#flatten' => TRUE,
'#prefix' => '<div id="geocoder-plugin-settings">',
'#suffix' => '</div>',
]);
}
parent::buildExposeForm($form, $form_state);
}