public function SettingsForm::submitForm in Leaflet More Maps 8
Same name and namespace in other branches
- 2.1.x src/Form/SettingsForm.php \Drupal\leaflet_more_maps\Form\SettingsForm::submitForm()
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides ConfigFormBase::submitForm
File
- src/
Form/ SettingsForm.php, line 136
Class
- SettingsForm
- Form to enter global settings and to assemble custom maps from overlays.
Namespace
Drupal\leaflet_more_maps\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$custom_maps = $form_state
->getValue('map');
// Clear out the unticked boxes before saving the form.
foreach ($custom_maps as $i => $custom_map) {
$custom_map['layer-keys'] = array_filter($custom_map['layer-keys']);
if (empty($custom_map['map_key']) || empty($custom_map['layer_keys'])) {
unset($custom_maps[$i]);
}
}
$this
->config('leaflet_more_maps.settings')
->set('thunderforest_api_key', $form_state
->getValue('thunderforest_api_key'))
->set('mapbox_access_token', $form_state
->getValue('mapbox_access_token'))
->set('here_api_key', $form_state
->getValue('here_api_key'))
->set('leaflet_more_maps_custom_maps', $custom_maps)
->save();
parent::submitForm($form, $form_state);
// @todo Need to refresh config cache.
}