public function GeofieldProximityFilter::validateExposed in Geofield 8
Validate the exposed handler form
Overrides HandlerBase::validateExposed
File
- src/
Plugin/ views/ filter/ GeofieldProximityFilter.php, line 312
Class
- GeofieldProximityFilter
- Field handler to filter Geofields by proximity.
Namespace
Drupal\geofield\Plugin\views\filterCode
public function validateExposed(&$form, FormStateInterface $form_state) {
parent::validateExposed($form, $form_state);
$form_values = $form_state
->getValues();
$identifier = $this->options['expose']['identifier'];
// Validate the Distance field.
if (isset($form_values[$identifier]['value']) && (!empty($form_values[$identifier]['value']) && !is_numeric($form_values[$identifier]['value']))) {
$form_state
->setError($form[$identifier]['value'], $this
->t('The Distance value is not valid.'));
}
// Validate the Min and Max values.
if (isset($form_values[$identifier]['min']) && isset($form_values[$identifier]['max']) && $form_values[$identifier]['min'] > $form_values[$identifier]['max']) {
$form_state
->setError($form[$identifier]['min'], $this
->t('The Min value should be smaller than the Max value.'));
}
// Validate the Origin (not null) value, when the filter is required.
if ($this->options['expose']['required'] == TRUE) {
if (isset($form_values[$identifier]['source_configuration']['origin_address'])) {
$input_address = $form_values[$identifier]['source_configuration']['origin_address'];
if (empty($input_address)) {
$form_state
->setError($form[$identifier]['source_configuration']['origin_address'], $this
->t('The Origin Address is required'));
}
}
elseif (isset($form_values[$identifier]['source_configuration']['origin'])) {
$input_origin = $form_values[$identifier]['source_configuration']['origin'];
if ($this->sourcePlugin
->isEmptyLocation($input_origin['lat'], $input_origin['lon'])) {
$form_state
->setError($form[$identifier]['source_configuration']['origin'], $this
->t('The Origin (Lat/Lon) is required'));
}
}
}
}