You are here

public function FarmSettingsFarmInfoForm::buildForm in farmOS 2.x

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

modules/core/settings/src/Form/FarmSettingsFarmInfoForm.php, line 68

Class

FarmSettingsFarmInfoForm
Form for configuring basic farm info.

Namespace

Drupal\farm_settings\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {

  // Set the form title.
  $form['#title'] = $this
    ->t('Configure Farm Info');

  // Get the system.site config.
  $site = $this
    ->config('system.site');

  // Textfield to edit site name.
  $form['site_name'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Farm name'),
    '#default_value' => $site
      ->get('name'),
    '#maxlength' => 128,
    '#required' => TRUE,
  ];

  // Get the system.date config.
  $system_date = $this
    ->config('system.date');

  // Get countries.
  $countries = $this->countryManager
    ->getList();

  // Default country select.
  $form['default_country'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Default country'),
    '#empty_value' => '',
    '#default_value' => $system_date
      ->get('country.default'),
    '#options' => $countries,
    '#attributes' => [
      'class' => [
        'country-detect',
      ],
    ],
  ];

  // Get list of timezones.
  $timezones = system_time_zones();

  // Dropdown to select default timezone.
  $form['default_timezone'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Default timezone'),
    '#description' => $this
      ->t('The default timezone of the farmOS server. Note that users can configure individual timezones later.'),
    '#options' => $timezones,
    '#default_value' => $system_date
      ->get('timezone.default'),
    '#required' => TRUE,
  ];

  // Submit button.
  $form['actions'] = [
    '#type' => 'actions',
  ];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Save'),
  ];
  return $form;
}