You are here

function weather_display_config_form in Weather 7.3

Same name and namespace in other branches
  1. 7.2 weather.forms.inc \weather_display_config_form()

Create a configuration 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_config_form'
weather_menu in ./weather.module
Implements hook_menu().

File

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

Code

function weather_display_config_form($form, &$form_state, $display_type, $display_number = NULL) {
  module_load_include('inc', 'weather', 'weather.common');
  $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;
  }
  $config = weather_get_display_config($display_type, $display_number);

  // Prevent users from entering arbitrary system-wide display numbers:
  // If the user entered a non-existant number, $config->number will be empty.
  if ($display_type == 'system-wide' and empty($config->number)) {
    $mode = 'add';
    $display_number = NULL;
  }
  $form['config'] = array(
    '#type' => 'fieldset',
    '#title' => t('Display configuration'),
    '#description' => t('Customize the weather display.'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#tree' => TRUE,
  );
  $form['config']['temperature'] = array(
    '#type' => 'select',
    '#title' => t('Temperature'),
    '#description' => t('Unit for displaying temperatures.'),
    '#default_value' => $config->config['temperature'],
    '#options' => array(
      'celsius' => t('Celsius'),
      'fahrenheit' => t('Fahrenheit'),
      'celsiusfahrenheit' => t('Celsius / Fahrenheit'),
      'fahrenheitcelsius' => t('Fahrenheit / Celsius'),
    ),
  );
  $form['config']['windspeed'] = array(
    '#type' => 'select',
    '#title' => t('Wind speed'),
    '#description' => t('Unit for displaying wind speeds.'),
    '#default_value' => $config->config['windspeed'],
    '#options' => array(
      'kmh' => t('km/h'),
      'mph' => t('mph'),
      'knots' => t('Knots'),
      'mps' => t('meter/s'),
      'beaufort' => t('Beaufort'),
    ),
  );
  $form['config']['pressure'] = array(
    '#type' => 'select',
    '#title' => t('Pressure'),
    '#description' => t('Unit for displaying pressure.'),
    '#default_value' => $config->config['pressure'],
    '#options' => array(
      'hpa' => t('hPa'),
      'kpa' => t('kPa'),
      'inhg' => t('inHg'),
      'mmhg' => t('mmHg'),
    ),
  );
  $form['config']['distance'] = array(
    '#type' => 'select',
    '#title' => t('Distance'),
    '#description' => t('Unit for displaying distances.'),
    '#default_value' => $config->config['distance'],
    '#options' => array(
      'kilometers' => t('Kilometers'),
      'miles' => t('UK miles'),
    ),
  );
  $form['config']['show_sunrise_sunset'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show times of sunrise and sunset'),
    '#default_value' => $config->config['show_sunrise_sunset'],
    '#description' => t('Displays the times of sunrise and sunset. This is always the local time.'),
  );
  $form['config']['show_windchill_temperature'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show windchill temperature'),
    '#default_value' => $config->config['show_windchill_temperature'],
    '#description' => t('Displays the windchill temperature. This is how the temperature <q>feels like</q>. Note that windchill temperature is only defined for temperatures below 10 °C (50 °F) and wind speeds above 1.34 m/s (3 mph).'),
  );
  $form['config']['show_abbreviated_directions'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show abbreviated wind directions'),
    '#default_value' => $config->config['show_abbreviated_directions'],
    '#description' => t('Displays abbreviated wind directions like N, SE, or W instead of North, Southeast, or West.'),
  );
  $form['config']['show_directions_degree'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show degrees of wind directions'),
    '#default_value' => $config->config['show_directions_degree'],
    '#description' => t('Displays the degrees of wind directions, for example, North (20°).'),
  );
  $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;
}