You are here

public function SettingsForm::buildForm in Weather 8

Same name and namespace in other branches
  1. 2.0.x src/Form/SettingsForm.php \Drupal\weather\Form\SettingsForm::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/SettingsForm.php, line 98

Class

SettingsForm
Configure Weather settings for this site.

Namespace

Drupal\weather\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $this
    ->addWeatherDisplayOverview($form, $form_state);

  // Import/Reimport places.
  $form['import_places'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Import/Reimport places'),
  ];
  $form['import_places']['description'] = [
    '#type' => 'markup',
    '#prefix' => '<span>',
    '#markup' => $this
      ->t('After the installation, you need to import weather places into the system.'),
    '#suffix' => '</span>',
  ];
  $form['import_places']['import_places_submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Import places'),
  ];

  // Additional weather settings.
  $theme = $this
    ->config('system.theme')
    ->get('default');
  $theme_path = drupal_get_path('theme', $theme);
  $config = $this
    ->config('weather.settings');
  $form['weather_image_directory'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Directory for custom images'),
    '#description' => $this
      ->t('Use custom images for displaying weather conditions. The name of this directory can be chosen freely. It will be searched in your active theme (currently %theme_path).', [
      '%theme_path' => $theme_path,
    ]),
    '#default_value' => $config
      ->get('weather_image_directory', ''),
  ];
  $options = [
    1,
    2,
    3,
    4,
    5,
    6,
    7,
    8,
    9,
    10,
    11,
    12,
    13,
    14,
  ];
  $form['weather_forecast_days'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Number of forecast days'),
    '#description' => $this
      ->t('You can configure the number of days for the forecast displays in blocks.'),
    '#default_value' => $config
      ->get('weather_forecast_days', '2'),
    '#options' => array_combine($options, $options),
  ];
  return parent::buildForm($form, $form_state);
}