YandexMapsSettings.php in Geolocation Field 8.2
File
modules/geolocation_yandex/src/Form/YandexMapsSettings.php
View source
<?php
namespace Drupal\geolocation_yandex\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class YandexMapsSettings extends ConfigFormBase {
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->configFactory
->get('yandex_maps.settings');
$form['key'] = [
'#type' => 'textfield',
'#title' => $this
->t('Yandex Maps Key'),
'#default_value' => $config
->get('key'),
'#description' => $this
->t('Yandex Maps requires users to sign up at <a href="https://developer.tech.yandex.ru/">developer.tech.yandex.ru</a>.'),
];
return parent::buildForm($form, $form_state);
}
public function getFormId() {
return 'geolocation_yandex_settings';
}
protected function getEditableConfigNames() {
return [
'yandex_maps.settings',
];
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this
->configFactory()
->getEditable('yandex_maps.settings');
$config
->set('key', $form_state
->getValue('key'));
$config
->save();
\Drupal::messenger()
->addMessage($this
->t('The configuration options have been saved.'));
drupal_flush_all_caches();
}
}