You are here

function weather_custom_block_form in Weather 5

Same name and namespace in other branches
  1. 5.6 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 452
Display <acronym title="METeorological Aerodrome Report">METAR</acronym> weather data from anywhere in the world

Code

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

  // 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']),
    '#attributes' => array(
      'onchange' => "update_place('{$places_url}')",
    ),
  );

  // set up a selection box with all place names of the selected country
  $form['icao'] = 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'],
    '#attributes' => array(
      'onchange' => 'update_icao()',
    ),
    // 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['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' => 'select',
    '#title' => t('Display units'),
    '#default_value' => $config['units'],
    '#description' => t('Show values of temperature, speed etc. in metric or imperial units.'),
    '#options' => array(
      'metric' => t('metric'),
      'imperial' => t('imperial'),
    ),
  );
  $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'),
  );
  $form['delete'] = array(
    '#type' => 'submit',
    '#value' => t('Delete configuration'),
  );
  return $form;
}