You are here

public function LiveWeatherSettingsForm::buildForm in Live Weather 8

Same name and namespace in other branches
  1. 8.2 src/Form/LiveWeatherSettingsForm.php \Drupal\live_weather\Form\LiveWeatherSettingsForm::buildForm()

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

src/Form/LiveWeatherSettingsForm.php, line 36
Contains \Drupal\live_weather\Form\LiveWeatherSettingsForm.

Class

LiveWeatherSettingsForm
Controller location for Live Weather Settings Form.

Namespace

Drupal\live_weather\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $settings = $this->configFactory
    ->get('live_weather.settings')
    ->get('settings');
  $form['#tree'] = TRUE;
  $form['settings']['unit'] = array(
    '#type' => 'select',
    '#title' => 'Unit',
    '#options' => array(
      'F' => t('Fahrenheit'),
      'C' => t('Celsius'),
    ),
    '#default_value' => $settings['unit'],
    '#description' => t('Select Fahrenheit or Celsius for temperature unit.'),
  );
  $form['settings']['image'] = array(
    '#type' => 'select',
    '#title' => 'Image',
    '#options' => array(
      FALSE => t('No'),
      TRUE => t('Yes'),
    ),
    '#default_value' => $settings['image'],
    '#description' => t('Select Yes to show Forcast Image.'),
  );
  $form['settings']['wind'] = array(
    '#type' => 'select',
    '#title' => 'Wind',
    '#options' => array(
      FALSE => t('No'),
      TRUE => t('Yes'),
    ),
    '#default_value' => $settings['wind'],
    '#description' => t('Select Yes to show wind speed.'),
  );
  $form['settings']['humidity'] = array(
    '#type' => 'select',
    '#title' => 'Humidity',
    '#options' => array(
      FALSE => t('No'),
      TRUE => t('Yes'),
    ),
    '#default_value' => $settings['humidity'],
    '#description' => t('Select Yes to show humidity level.'),
  );
  $form['settings']['visibility'] = array(
    '#type' => 'select',
    '#title' => 'Visibility',
    '#options' => array(
      FALSE => t('No'),
      TRUE => t('Yes'),
    ),
    '#default_value' => $settings['visibility'],
    '#description' => t('Select Yes to show visibility level.'),
  );
  $form['settings']['sunrise'] = array(
    '#type' => 'select',
    '#title' => 'Sunrise',
    '#options' => array(
      FALSE => t('No'),
      TRUE => t('Yes'),
    ),
    '#default_value' => $settings['sunrise'],
    '#description' => t('Select Yes to show sunrise time.'),
  );
  $form['settings']['sunset'] = array(
    '#type' => 'select',
    '#title' => 'Sunset',
    '#options' => array(
      FALSE => t('No'),
      TRUE => t('Yes'),
    ),
    '#default_value' => $settings['sunset'],
    '#description' => t('Select Yes to show sunset time.'),
  );
  $form['settings']['cache'] = array(
    '#type' => 'select',
    '#title' => 'Cache',
    '#options' => array(
      0 => t('No Cache'),
      1800 => t('30 min'),
      3600 => t('1 hour'),
      86400 => t('One day'),
    ),
    '#default_value' => $settings['cache'],
    '#description' => t('Time for cache the block'),
  );
  return parent::buildForm($form, $form_state);
}