You are here

function weather_custom_block_form in Weather 5.6

Same name and namespace in other branches
  1. 5 weather.module \weather_custom_block_form()
  2. 6.5 weather.module \weather_custom_block_form()

Construct the configuration form for a weather block

1 string reference to 'weather_custom_block_form'
weather_custom_block in ./weather.module
Show a configuration page for a custom weather block

File

./weather.module, line 612
Display <acronym title="METeorological Aerodrome Report">METAR</acronym> weather data from anywhere in the world

Code

function weather_custom_block_form($uid, $cid, $config) {

  // set up a selection box with all countries
  $form['country'] = array(
    '#prefix' => '<div id="weather-js-show-selectbox" style="display:none;">',
    '#type' => 'select',
    '#title' => t('Country'),
    '#description' => t('Select a country to narrow down your search.'),
    '#default_value' => $config['country'],
    '#options' => drupal_map_assoc($config['countries']),
  );

  // set up a selection box with all place names of the selected country
  $form['place'] = array(
    '#type' => 'select',
    '#title' => t('Place'),
    '#description' => t('Select a place in that country for the weather display.'),
    '#default_value' => $config['icao'],
    '#options' => $config['places'],
    '#suffix' => '</div>',
    // we need to skip the check of valid options, because they get
    // modified with AJAX after a new country has been selected.
    '#DANGEROUS_SKIP_CHECK' => true,
  );
  $form['icao'] = array(
    '#type' => 'textfield',
    '#title' => t('ICAO code'),
    '#default_value' => $config['icao'],
    '#description' => t('Enter the 4-letter ICAO code of the weather station. If you first need to look up the code, you can use !url_1 or !url_2. Please note that not all stations listed at those URLs are providing weather data and thus may not be supported by this module.', array(
      '!url_1' => l('airlinecodes.co.uk', 'http://www.airlinecodes.co.uk/aptcodesearch.asp'),
      '!url_2' => l('notams.jcs.mil', 'https://www.notams.jcs.mil/common/icao/index.html'),
    )),
    '#required' => true,
    '#size' => '5',
  );
  $form['real_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Real name for the selected place'),
    '#default_value' => $config['real_name'],
    '#description' => t('You may enter another name for the place selected above.'),
    '#required' => true,
    '#size' => '30',
  );
  $form['units'] = array(
    '#type' => 'fieldset',
    '#title' => t('Display units'),
    '#description' => t('You can specify which units should be used for displaying the data.'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#tree' => TRUE,
  );
  $form['units']['temperature'] = array(
    '#type' => 'select',
    '#title' => t('Temperature'),
    '#default_value' => $config['units']['temperature'],
    '#options' => array(
      'celsius' => t('Celsius'),
      'fahrenheit' => t('Fahrenheit'),
    ),
  );
  $form['units']['windspeed'] = array(
    '#type' => 'select',
    '#title' => t('Wind speed'),
    '#default_value' => $config['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' => $config['units']['pressure'],
    '#options' => array(
      'hpa' => t('hPa'),
      'inhg' => t('inHg'),
      'mmhg' => t('mmHg'),
    ),
  );
  $form['units']['visibility'] = array(
    '#type' => 'select',
    '#title' => t('Visibility'),
    '#default_value' => $config['units']['visibility'],
    '#options' => array(
      'kilometers' => t('kilometers'),
      'miles' => t('UK miles'),
    ),
  );
  $form['settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('Display settings'),
    '#description' => t('You can customize the display of the block.'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#tree' => TRUE,
  );
  $form['settings']['show_unconverted_metar'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show unconverted METAR data'),
    '#default_value' => $config['settings']['show_unconverted_metar'],
    '#description' => t('Displays the original data of the METAR report.'),
  );
  $form['settings']['show_abbreviated_directions'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show abbreviated wind directions'),
    '#default_value' => $config['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' => $config['settings']['show_directions_degree'],
    '#description' => t('Displays the degrees of wind directions, e.g. North (20°).'),
  );
  $form['settings']['show_sunrise_sunset'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show time of sunrise and sunset'),
    '#default_value' => $config['settings']['show_sunrise_sunset'],
    '#description' => t('Displays the time of sunrise and sunset as Greenwich Mean Time (GMT). Therefore, the sunset may be earlier than the sunrise.'),
  );
  $form['settings']['show_compact_block'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show compact block'),
    '#default_value' => $config['settings']['show_compact_block'],
    '#description' => t('Displays only the name, condition, and temperature of the weather station.'),
  );
  $form['weight'] = array(
    '#type' => 'weight',
    '#title' => t('Weight'),
    '#default_value' => $config['weight'],
    '#description' => t('Optional. In the block, the heavier locations will sink and the lighter locations will be positioned nearer the top. Locations with equal weights are sorted alphabetically.'),
  );
  $form['uid'] = array(
    '#type' => 'value',
    '#value' => $uid,
  );
  $form['cid'] = array(
    '#type' => 'value',
    '#value' => $cid,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
  );
  return $form;
}