public function OriginFromProximityFilter::buildOptionsForm in Geofield 8
Builds the specific form elements for the geofield proximity plugin.
Parameters
array $form: The form element to build.
\Drupal\Core\Form\FormStateInterface $form_state: The form state.
array $options_parents: The values parents.
bool $is_exposed: The check/differentiate if it is part of an exposed form.
Overrides GeofieldProximitySourceBase::buildOptionsForm
File
- src/
Plugin/ GeofieldProximitySource/ OriginFromProximityFilter.php, line 89
Class
- OriginFromProximityFilter
- Defines 'Geofield Custom Origin' plugin.
Namespace
Drupal\geofield\Plugin\GeofieldProximitySourceCode
public function buildOptionsForm(array &$form, FormStateInterface $form_state, array $options_parents, $is_exposed = FALSE) {
$user_input = $form_state
->getUserInput();
$proximity_filters_sources = $this
->getAvailableProximityFilters();
$user_input_proximity_filter = isset($user_input['options']['source_configuration']['source_proximity_filter']) ? $user_input['options']['source_configuration']['source_proximity_filter'] : current(array_keys($proximity_filters_sources));
$source_proximity_filter = isset($this->configuration['source_proximity_filter']) ? $this->configuration['source_proximity_filter'] : $user_input_proximity_filter;
if (!empty($proximity_filters_sources)) {
$form['source_proximity_filter'] = [
'#type' => 'select',
'#title' => $this
->t('Source Proximity Filter'),
'#description' => $this
->t('Select the Geofield Proximity filter to use as the starting point for calculating proximity.'),
'#options' => $this
->getAvailableProximityFilters(),
'#default_value' => $source_proximity_filter,
'#ajax' => [
'callback' => [
static::class,
'sourceProximityFilterUpdate',
],
'effect' => 'fade',
],
];
}
else {
$form['source_proximity_filter_warning'] = [
'#type' => 'html_tag',
'#tag' => 'div',
'#value' => $this
->t('No Geofield Proximity Filter found. At least one should be set for this Proximity Field be able to work.'),
"#attributes" => [
'class' => [
'proximity-filter-warning',
'red',
],
],
];
$form_state
->setError($form['source_proximity_filter_warning'], $this
->t('This Proximity Field cannot work. Dismiss this and add & setup a Geofield Proximity Filter before.'));
}
}