HereMapsSettings.php in Geolocation Field 8.2
File
modules/geolocation_here/src/Form/HereMapsSettings.php
View source
<?php
namespace Drupal\geolocation_here\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class HereMapsSettings extends ConfigFormBase {
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->configFactory
->get('here_maps.settings');
$form['app_id'] = [
'#type' => 'textfield',
'#title' => $this
->t('HERE Maps App ID'),
'#default_value' => $config
->get('app_id'),
'#description' => $this
->t('HERE Maps requires users to sign up at <a href="https://developer.here.com">developers.here.com</a>.'),
];
$form['app_code'] = [
'#type' => 'textfield',
'#title' => $this
->t('HERE Maps App Code'),
'#default_value' => $config
->get('app_code'),
];
return parent::buildForm($form, $form_state);
}
public function getFormId() {
return 'geolocation_here_settings';
}
protected function getEditableConfigNames() {
return [
'here_maps.settings',
];
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this
->configFactory()
->getEditable('here_maps.settings');
$config
->set('app_id', $form_state
->getValue('app_id'));
$config
->set('app_code', $form_state
->getValue('app_code'));
$config
->save();
\Drupal::messenger()
->addMessage($this
->t('The configuration options have been saved.'));
drupal_flush_all_caches();
}
}