View source
<?php
namespace Drupal\geofield\Plugin\GeofieldProximitySource;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Component\Render\FormattableMarkup;
class ClientLocationOriginFilter extends ManualOriginDefault {
public function buildOptionsForm(array &$form, FormStateInterface $form_state, array $options_parents, $is_exposed = FALSE) {
$form['#attributes'] = [
'class' => [
'proximity-origin-client',
],
];
$form["origin"] = [
'#title' => $this
->t('Client Coordinates'),
'#type' => 'geofield_latlon',
'#description' => $this
->t('Value in decimal degrees. Use dot (.) as decimal separator.'),
'#default_value' => [
'lat' => '',
'lon' => '',
],
'#attributes' => [
'class' => [
'visually-hidden',
],
],
];
if ($this->viewHandler->configuration['id'] == 'geofield_proximity_filter' && !$is_exposed) {
$form['origin_summary_flag'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Show the Client Origin coordinates as summary in the Exposed Form'),
'#default_value' => isset($this->configuration['origin_summary_flag']) ? $this->configuration['origin_summary_flag'] : TRUE,
];
}
if ($is_exposed) {
$form['origin']['#attached']['library'][] = 'geofield/geolocation';
if (isset($this->configuration['origin_summary_flag']) && $this->configuration['origin_summary_flag']) {
$form['origin_summary'] = [
"#type" => 'html_tag',
"#tag" => 'div',
'#value' => $this
->t('from Latitude: @lat and Longitude: @lon.', [
'@lat' => new FormattableMarkup('<span class="geofield-lat-summary">@lat</span>', [
'@lat' => $this
->t('undefined'),
]),
'@lon' => new FormattableMarkup('<span class="geofield-lon-summary">@lon</span>', [
'@lon' => $this
->t('undefined'),
]),
]),
];
}
}
}
}