You are here

class QuantitySettingsForm in farmOS 2.x

Provides a quantity settings form.

Hierarchy

Expanded class hierarchy of QuantitySettingsForm

1 string reference to 'QuantitySettingsForm'
quantity.routing.yml in modules/core/quantity/quantity.routing.yml
modules/core/quantity/quantity.routing.yml

File

modules/core/quantity/src/Form/QuantitySettingsForm.php, line 11

Namespace

Drupal\quantity\Form
View source
class QuantitySettingsForm extends ConfigFormbase {

  /**
   * Config settings.
   *
   * @var string
   */
  const SETTINGS = 'quantity.settings';

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'quantity_settings';
  }

  /**
   * {@inheritdoc}
   */
  protected function getEditableConfigNames() {
    return [
      static::SETTINGS,
    ];
  }

  /**
   * {@inheritdoc}
   */
  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);
  }

  /**
   * {@inheritdoc}
   */
  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);
  }

}

Members