GeolocationSettings.php in GeoIP API 8.2
File
src/Form/GeolocationSettings.php
View source
<?php
namespace Drupal\geoip\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class GeolocationSettings extends ConfigFormBase {
protected function getEditableConfigNames() {
return [
'geoip.geolocation',
];
}
public function getFormId() {
return 'geoip_geolocation_settings';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('geoip.geolocation');
$form['plugin_id'] = [
'#type' => 'tableselect',
'#multiple' => FALSE,
'#header' => [
'label' => $this
->t('Label'),
'description' => $this
->t('Description'),
],
'#options' => [],
'#default_value' => $config
->get('plugin_id'),
];
foreach (\Drupal::service('plugin.manager.geolocator')
->getDefinitions() as $plugin_id => $definition) {
$form['plugin_id']['#options'][$plugin_id] = [
'label' => $definition['label'],
'description' => $definition['description'],
];
}
$form['debug'] = [
'#type' => 'radios',
'#title' => $this
->t('Enable debugging logs'),
'#options' => [
$this
->t('No'),
$this
->t('Yes'),
],
'#default_value' => (int) $config
->get('debug'),
];
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this
->config('geoip.geolocation')
->set('plugin_id', $form_state
->getValue('plugin_id'))
->set('debug', $form_state
->getValue('debug'))
->save();
parent::submitForm($form, $form_state);
}
}