QuantitySettingsForm.php in farmOS 2.x
File
modules/core/quantity/src/Form/QuantitySettingsForm.php
View source
<?php
namespace Drupal\quantity\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class QuantitySettingsForm extends ConfigFormbase {
const SETTINGS = 'quantity.settings';
public function getFormId() {
return 'quantity_settings';
}
protected function getEditableConfigNames() {
return [
static::SETTINGS,
];
}
public function buildForm(array $form, FormStateinterface $form_state) {
$config = $this
->config(static::SETTINGS);
$form['system_of_measurement'] = [
'#type' => 'radios',
'#title' => $this
->t('System of measurement'),
'#description' => $this
->t('Select the system of measurement you would like to use in farmOS. Changing this setting after data has been entered is not recommended.'),
'#options' => [
'metric' => $this
->t('Metric'),
'us' => $this
->t('US/Imperial'),
],
'#default_value' => $config
->get('system_of_measurement'),
];
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->configFactory
->getEditable(static::SETTINGS)
->set('system_of_measurement', $form_state
->getValue('system_of_measurement'))
->save();
parent::submitForm($form, $form_state);
}
}