You are here

function weather_display_settings_form in Weather 7

Create a settings form for a weather display.

Parameters

string $display_type: Type of the display (for example, system-wide, user, location, ...).

string $display_number: Number of the display or NULL.

Return value

array Form array for the weather display.

1 string reference to 'weather_display_settings_form'
weather_menu in ./weather.module
Implement hook_menu().

File

./weather.forms.inc, line 145
Provide forms for configuration of weather displays.

Code

function weather_display_settings_form($form, &$form_state, $display_type, $display_number = NULL) {
  $mode = 'edit';
  if ($display_number == 'add') {

    // Preserve the mode for this form.
    $mode = 'add';
    $display_number = NULL;
  }
  if ($display_type == 'default') {
    $mode = 'default';
    $display_number = 1;
  }
  $settings = weather_get_display_settings($display_type, $display_number);

  // Prevent users from entering arbitrary system-wide display numbers:
  // If the user entered a non-existant number, $settings->number will be empty.
  if ($display_type == 'system-wide' and empty($settings->number)) {
    $mode = 'add';
    $display_number = NULL;
  }
  $form['units'] = array(
    '#type' => 'fieldset',
    '#title' => t('Display units'),
    '#description' => t('Specify which units should be used for displaying the weather data.'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#tree' => TRUE,
  );
  $form['units']['temperature'] = array(
    '#type' => 'select',
    '#title' => t('Temperature'),
    '#default_value' => $settings->units['temperature'],
    '#options' => array(
      'celsius' => t('Celsius'),
      'fahrenheit' => t('Fahrenheit'),
      'celsiusfahrenheit' => t('Celsius / Fahrenheit'),
      'fahrenheitcelsius' => t('Fahrenheit / Celsius'),
    ),
  );
  $form['units']['windspeed'] = array(
    '#type' => 'select',
    '#title' => t('Wind speed'),
    '#default_value' => $settings->units['windspeed'],
    '#options' => array(
      'kmh' => t('km/h'),
      'mph' => t('mph'),
      'knots' => t('Knots'),
      'mps' => t('meter/s'),
      'beaufort' => t('Beaufort'),
    ),
  );
  $form['units']['pressure'] = array(
    '#type' => 'select',
    '#title' => t('Pressure'),
    '#default_value' => $settings->units['pressure'],
    '#options' => array(
      'hpa' => t('hPa'),
      'kpa' => t('kPa'),
      'inhg' => t('inHg'),
      'mmhg' => t('mmHg'),
    ),
  );
  $form['units']['distance'] = array(
    '#type' => 'select',
    '#title' => t('Distance (for example, Visibility)'),
    '#default_value' => $settings->units['distance'],
    '#options' => array(
      'kilometers' => t('Kilometers'),
      'miles' => t('UK miles'),
    ),
  );
  $form['settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('Display settings'),
    '#description' => t('Customize the weather display.'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#tree' => TRUE,
  );
  $form['settings']['data'] = array(
    '#type' => 'select',
    '#multiple' => TRUE,
    '#title' => t('Data to show'),
    '#description' => t('Select which weather data should be shown in the display. Please note that some weather stations may not provide all data at all times. Therefore, some weather data might not be displayed even though it is selected.'),
    '#default_value' => $settings->settings['data'],
    '#options' => array(
      'temperature' => t('Temperature'),
      'wind' => t('Wind information'),
      'pressure' => t('Pressure'),
      'humidity' => t('Rel. Humidity'),
      'visibility' => t('Visibility'),
      'suninfo' => t('Times of sunrise and sunset'),
      'metar' => t('Original METAR report'),
    ),
  );
  $form['settings']['show_apparent_temperature'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show apparent temperature'),
    '#default_value' => $settings->settings['show_apparent_temperature'],
    '#description' => t('Displays the apparent temperature. This is how the temperature <q>feels like</q>. For cold and windy conditions, the windchill is calculated. For hot and humid conditions, the heat index is calculated. Note that windchill temperature is only defined for temperatures below 10 °C (50 °F) and wind speeds above 5 km/h (3 mph). The heat index is only defined for temperatures above 26.7 °C (80 °F) and a relative humidity above 40%.'),
  );
  $form['settings']['show_abbreviated_directions'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show abbreviated wind directions'),
    '#default_value' => $settings->settings['show_abbreviated_directions'],
    '#description' => t('Displays abbreviated wind directions like N, SE, or W instead of North, Southeast, or West.'),
  );
  $form['settings']['show_directions_degree'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show degrees of wind directions'),
    '#default_value' => $settings->settings['show_directions_degree'],
    '#description' => t('Displays the degrees of wind directions, for example, North (20°).'),
  );
  $form['settings']['show_compact_block'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show compact block'),
    '#default_value' => $settings->settings['show_compact_block'],
    '#description' => t('Displays only the name, condition, and temperature of the weather station.'),
  );
  $form['type'] = array(
    '#type' => 'value',
    '#value' => $display_type,
  );
  $form['number'] = array(
    '#type' => 'value',
    '#value' => $display_number,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );

  // Do not show the 'delete' button if not in 'edit' mode.
  if ($mode == 'edit') {
    $form['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete'),
      '#submit' => array(
        'weather_display_delete_submit',
      ),
    );
  }

  // Show a 'reset' button if editing the default display.
  if ($mode == 'default') {
    $form['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Reset'),
      '#submit' => array(
        'weather_display_delete_confirm_submit',
      ),
    );
  }
  return $form;
}