You are here

public function GeolocationSettings::submitForm in Geolocation Field 8

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/GeolocationSettings.php, line 172

Class

GeolocationSettings
Implements the GeolocationGoogleMapAPIkey form controller.

Namespace

Drupal\geolocation\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $config = $this
    ->configFactory()
    ->getEditable('geolocation.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'));
  $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_set_message($this
    ->t('The configuration options have been saved.'));
}