public static function GeocoderManager::addGeocoderSettingsFormAjax in Geolocation Field 8
Same name and namespace in other branches
- 8.3 src/GeocoderManager.php \Drupal\geolocation\GeocoderManager::addGeocoderSettingsFormAjax()
- 8.2 src/GeocoderManager.php \Drupal\geolocation\GeocoderManager::addGeocoderSettingsFormAjax()
Return settings array for geocoder after select change.
Parameters
array $form: Form.
\Drupal\Core\Form\FormStateInterface $form_state: Current From State.
Return value
array|false Settings form.
File
- src/
GeocoderManager.php, line 104
Class
- GeocoderManager
- Search plugin manager.
Namespace
Drupal\geolocationCode
public static function addGeocoderSettingsFormAjax(array $form, FormStateInterface $form_state) {
$triggering_element = $form_state
->getTriggeringElement()['#parents'];
array_pop($triggering_element);
$target = $triggering_element;
$target[] = 'plugin_id';
$plugin_id = $form_state
->getValue($target, '');
$target = $triggering_element;
$target[] = 'settings';
$geocoder_settings = $form_state
->getValue($target, []);
/** @var \Drupal\geolocation\GeocoderInterface $geocoder_plugin */
$geocoder_plugin = \Drupal::service('plugin.manager.geolocation.geocoder')
->getGeocoder($plugin_id, $geocoder_settings);
if (empty($geocoder_plugin)) {
$return = [
'#type' => 'html_tag',
'#tag' => 'span',
'#value' => t('Non-existing geocoder plugin requested.'),
];
}
else {
$geocoder_settings_form = $geocoder_plugin
->getOptionsForm();
if (!empty($geocoder_settings_form)) {
$return = $geocoder_settings_form;
}
else {
$return = [
'#type' => 'html_tag',
'#tag' => 'span',
'#value' => t("No settings available."),
];
}
}
$return = array_merge_recursive($return, [
'#prefix' => '<div id="geocoder-plugin-settings">',
'#suffix' => '</div>',
]);
return $return;
}