You are here

public function WeatherHourlyBlock::blockForm in Wunderground weather 8

Overrides BlockPluginTrait::blockForm

File

src/Plugin/Block/WeatherHourlyBlock.php, line 69
Contains \Drupal\wunderground_weather\Plugin\Block\WeatherHourlyBlock.

Class

WeatherHourlyBlock
Provides a with an hourly weather forecast.

Namespace

Drupal\wunderground_weather\Plugin\Block

Code

public function blockForm($form, FormStateInterface $form_state) {
  $config = $this
    ->getConfiguration();
  $form['location'] = [
    '#type' => 'fieldset',
    '#title' => t('Location'),
  ];

  // Autocomplete to get location.
  $form['location']['location'] = [
    '#title' => t('Location path'),
    '#type' => 'textfield',
    '#description' => t('Search for your city to determine the Wunderground location path.'),
    '#maxlength' => 120,
    '#required' => TRUE,
    '#autocomplete_route_name' => 'wunderground_weather.autocomplete',
    '#default_value' => isset($config['location']) ? $config['location'] : '',
  ];
  $form['temperature_scale'] = [
    '#title' => t('Show temperature in'),
    '#type' => 'radios',
    '#options' => [
      'c' => t('Celsius'),
      'f' => t('Fahrenheit'),
    ],
    '#default_value' => empty($this->configuration['temperature_scale']) ? 'c' : $this->configuration['temperature_scale'],
  ];
  $form['windspeed_scale'] = [
    '#title' => t('Show wind speed in'),
    '#type' => 'radios',
    '#options' => [
      'bft' => t('Beaufort'),
      'mph' => t('Miles per hour'),
      'kph' => t('Kilometers per hour'),
    ],
    '#default_value' => isset($config['windspeed_scale']) ? $config['windspeed_scale'] : 'bft',
  ];
  $settings_forecast_defaults = [
    'image' => 'image',
    'conditions' => 'conditions',
    'temperature' => 'temperature',
    'rain' => 'rain',
    'wind' => 'wind',
  ];
  $form['used_fields'] = [
    '#title' => t('Fields'),
    '#type' => 'checkboxes',
    '#options' => $this
      ->getAvailableFields(),
    '#default_value' => isset($config['forecast_fields']) ? $config['forecast_fields'] : $settings_forecast_defaults,
  ];
  $form['number_of_hours'] = [
    '#title' => t('How many hours would you like to display'),
    '#description' => t('You can display up to 36 hours'),
    '#type' => 'number',
    '#default_value' => isset($config['number_of_hours']) ? $config['number_of_hours'] : 3,
    '#size' => 2,
    '#maxlength' => 2,
    '#required' => TRUE,
  ];
  $icons = [];
  foreach (range('a', 'k') as $set) {
    $icons[$set] = $this->wundergroundWeatherManager
      ->getIconSetSample($set);
  }
  $form['icon_set'] = [
    '#titel' => t('Select an icons set'),
    '#type' => 'radios',
    '#options' => $icons,
    '#default_value' => isset($config['icon_set']) ? $config['icon_set'] : 'k',
  ];
  return $form;
}