MapboxSettingsForm.php in farmOS 2.x
File
modules/core/map/modules/mapbox/src/Form/MapboxSettingsForm.php
View source
<?php
namespace Drupal\farm_map_mapbox\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class MapboxSettingsForm extends ConfigFormbase {
const SETTINGS = 'farm_map_mapbox.settings';
public function getFormId() {
return 'farm_map_mapbox_settings';
}
protected function getEditableConfigNames() {
return [
static::SETTINGS,
];
}
public function buildForm(array $form, FormStateinterface $form_state) {
$config = $this
->config(static::SETTINGS);
$form['api_key'] = [
'#type' => 'textfield',
'#title' => $this
->t('Mapbox API Key'),
'#description' => $this
->t('Enter your Mapbox API key.'),
'#default_value' => $config
->get('api_key'),
];
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->configFactory
->getEditable(static::SETTINGS)
->set('api_key', $form_state
->getValue('api_key'))
->save();
parent::submitForm($form, $form_state);
}
}