function weather_custom_block_form in Weather 6.5
Same name and namespace in other branches
- 5.6 weather.module \weather_custom_block_form()
- 5 weather.module \weather_custom_block_form()
Construct the configuration form for a weather block
2 string references to 'weather_custom_block_form'
- weather_custom_block in ./
weather.module - Show a configuration page for a custom weather block
- weather_js in ./
weather.module - Return a new place selection box based on the country selection
File
- ./
weather.module, line 778 - Display <acronym title="METeorological Aerodrome Report">METAR</acronym> weather data from anywhere in the world
Code
function weather_custom_block_form($dummy, $uid, $cid, $config) {
// set up a selection box with all countries
$form['country'] = array(
'#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']),
'#ahah' => array(
'path' => 'weather/js',
'wrapper' => 'edit-place-wrapper',
),
);
// 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'],
);
$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'),
'celsiusfahrenheit' => t('Celsius / Fahrenheit'),
'fahrenheitcelsius' => t('Fahrenheit / Celsius'),
'dont-display' => t('Don\'t display'),
),
);
$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'),
'dont-display' => t('Don\'t display'),
),
);
$form['units']['pressure'] = array(
'#type' => 'select',
'#title' => t('Pressure'),
'#default_value' => $config['units']['pressure'],
'#options' => array(
'hpa' => t('hPa'),
'kpa' => t('kPa'),
'inhg' => t('inHg'),
'mmhg' => t('mmHg'),
'dont-display' => t('Don\'t display'),
),
);
$form['units']['humidity'] = array(
'#type' => 'select',
'#title' => t('Rel. Humidity'),
'#default_value' => $config['units']['humidity'],
'#options' => array(
'display' => t('Display'),
'dont-display' => t('Don\'t display'),
),
);
$form['units']['visibility'] = array(
'#type' => 'select',
'#title' => t('Visibility'),
'#default_value' => $config['units']['visibility'],
'#options' => array(
'kilometers' => t('kilometers'),
'miles' => t('UK miles'),
'dont-display' => t('Don\'t display'),
),
);
$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_windchill'] = array(
'#type' => 'checkbox',
'#title' => t('Show windchill temperature'),
'#default_value' => $config['settings']['show_windchill'],
'#description' => t('Calculates the temperature resulting from windchill. This is how the temperature <q>feels like</q>.'),
);
$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.'),
);
// Construct timezones
$timezones = array(
'gmt' => t('GMT'),
'drupal' => t('Drupal'),
);
$system_timezones = _system_zonelist();
foreach ($system_timezones as $seconds_offset => $date) {
$timezones[$seconds_offset] = sprintf("%+03d:%02d", $seconds_offset / 3600, abs($seconds_offset % 3600) / 60);
}
$form['settings']['sunrise_sunset_timezone'] = array(
'#type' => 'select',
'#title' => t('Timezone for sunrise and sunset'),
'#default_value' => $config['settings']['sunrise_sunset_timezone'],
'#description' => t('Choose either Greenwich Mean Time (GMT), Drupal\'s standard timezone as set in the configuration, or a custom timezone.'),
'#options' => $timezones,
);
$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;
}