SettingsForm.php in Geocoder 8.3
File
src/Form/SettingsForm.php
View source
<?php
namespace Drupal\geocoder\Form;
use Drupal\Core\Config\TypedConfigManagerInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class SettingsForm extends ConfigFormBase {
protected $typedConfigManager;
public function __construct(ConfigFactoryInterface $config_factory, TypedConfigManagerInterface $typedConfigManager) {
parent::__construct($config_factory);
$this->typedConfigManager = $typedConfigManager;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('config.typed'));
}
public function getFormId() {
return 'geocoder_settings';
}
protected function getEditableConfigNames() {
return [
'geocoder.settings',
];
}
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('geocoder.settings');
$geocoder_config_schema = $this->typedConfigManager
->getDefinition('geocoder.settings') + [
'mapping' => [],
];
$geocoder_config_schema = $geocoder_config_schema['mapping'];
$form['#attached']['library'] = [
'geocoder/general',
];
$form['geocoder_presave_disabled'] = [
'#type' => 'checkbox',
'#title' => $geocoder_config_schema['geocoder_presave_disabled']['label'],
'#description' => $geocoder_config_schema['geocoder_presave_disabled']['description'],
'#default_value' => $config
->get('geocoder_presave_disabled'),
];
$form['cache'] = [
'#type' => 'checkbox',
'#title' => $geocoder_config_schema['cache']['label'],
'#description' => $geocoder_config_schema['cache']['description'],
'#default_value' => $config
->get('cache'),
];
return parent::buildForm($form, $form_state);
}
public function validateForm(array &$form, FormStateInterface $form_state) {
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$form_state_values = $form_state
->getValues();
$config = $this
->config('geocoder.settings');
$config
->set('geocoder_presave_disabled', $form_state_values['geocoder_presave_disabled']);
$config
->set('cache', $form_state_values['cache']);
$config
->save();
parent::submitForm($form, $form_state);
}
}