You are here

public function GeolocationGoogleMapsSettings::submitForm in Geolocation Field 8.3

Same name and namespace in other branches
  1. 8.2 modules/geolocation_google_maps/src/Form/GeolocationGoogleMapsSettings.php \Drupal\geolocation_google_maps\Form\GeolocationGoogleMapsSettings::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

modules/geolocation_google_maps/src/Form/GeolocationGoogleMapsSettings.php, line 196

Class

GeolocationGoogleMapsSettings
Implements the GeolocationGoogleMapAPIkey form controller.

Namespace

Drupal\geolocation_google_maps\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $config = $this
    ->configFactory()
    ->getEditable('geolocation_google_maps.settings');
  $config
    ->set('google_map_api_key', $form_state
    ->getValue('google_map_api_key'));
  $config
    ->set('google_map_api_server_key', $form_state
    ->getValue('google_map_api_server_key'));
  $config
    ->set('use_current_language', $form_state
    ->getValue('use_current_language'));
  $config
    ->set('china_mode', $form_state
    ->getValue('china_mode'));
  $config
    ->set('google_maps_base_url', $form_state
    ->getValue('google_maps_base_url'));
  $parameters = $form_state
    ->getValue('parameters');
  unset($parameters['libraries']['add']);
  $parameters['libraries'] = array_unique($parameters['libraries']);
  foreach ($parameters['libraries'] as $key => $library) {
    if (empty($library)) {
      unset($parameters['libraries'][$key]);
    }
  }
  $parameters['libraries'] = array_values($parameters['libraries']);
  $config
    ->set('google_map_custom_url_parameters', $parameters);
  $config
    ->save();

  // Confirmation on form submission.
  \Drupal::messenger()
    ->addMessage($this
    ->t('The configuration options have been saved.'));
  drupal_flush_all_caches();
}