You are here

function wunderground_weather_block_configure in Wunderground weather 7

Implements hook_block_configure().

File

./wunderground_weather.module, line 197
Wunderground weather module to display weather forecasts and current weather conditions in blocks.

Code

function wunderground_weather_block_configure($delta = '') {
  $form['draggable']['#theme'] = 'wunderground_weather_field_drag';
  $form['draggable']['fields']['#tree'] = TRUE;

  // Configuration for forecast blocks.
  for ($f = 1; $f <= variable_get('wunderground_weather_block_forecast_amount', '1'); $f++) {
    if ($delta == 'wunderground_weather_forecast_' . $f) {
      wunderground_weather_block_configure_location_fields($form, 'forecast', $f);
      $date_formats = array();
      $date_types = system_get_date_types();
      foreach ($date_types as $key => $value) {
        $date_formats[$value['type']] = t('@date_format format', array(
          '@date_format' => $value['title'],
        )) . ': ' . format_date(REQUEST_TIME, $value['type']);
      }
      $form['date'] = array(
        '#type' => 'fieldset',
        '#title' => t('Dates'),
        '#description' => t('Choose a date format'),
      );
      $form['date']['wunderground_weather_forecast_date_format_' . $f] = array(
        '#type' => 'select',
        '#title' => t('Date format'),
        '#options' => $date_formats,
        '#default_value' => variable_get('wunderground_weather_forecast_date_format_' . $f, 'medium'),
      );
      $serialized_fields = variable_get($delta . '_fields', FALSE);
      $block_fields = $serialized_fields ? unserialize($serialized_fields) : wunderground_weather_forecast_fields();
      $i = 0;
      foreach (wunderground_weather_forecast_fields() as $key => $value) {
        $form['draggable']['fields'][$key] = array(
          'name' => array(
            '#markup' => check_plain($value),
          ),
          'enabled' => array(
            '#type' => 'checkbox',
            '#default_value' => isset($block_fields[$key]['#enabled']) ? $block_fields[$key]['#enabled'] : TRUE,
          ),
          'weight' => array(
            '#type' => 'weight',
            '#title' => t('Weight'),
            '#default_value' => isset($block_fields[$key]['#weight']) ? $block_fields[$key]['#weight'] : $i,
            '#delta' => 6,
            '#title_display' => 'invisible',
          ),
          '#weight' => isset($block_fields[$key]['#weight']) ? $block_fields[$key]['#weight'] : $i,
        );
        ++$i;
      }
      $form['icons'] = array(
        '#type' => 'fieldset',
        '#title' => t('Icons'),
      );
      $alphas = range('a', 'k');
      foreach ($alphas as $letter) {
        $icon_options[$letter] = _wunderground_weather_get_icons_sample($letter);
      }
      $form['icons']['wunderground_weather_forecast_icons_' . $f] = array(
        '#type' => 'radios',
        '#title' => t('Select the icon set you want to use.'),
        '#options' => $icon_options,
        '#default_value' => variable_get('wunderground_weather_forecast_icons_' . $f, 'a'),
      );
    }
  }

  // Configuration for current weather condition blocks.
  for ($t = 1; $t <= variable_get('wunderground_weather_block_current_amount', '1'); $t++) {
    if ($delta == 'wunderground_weather_current_' . $t) {
      wunderground_weather_block_configure_location_fields($form, 'current', $t);
      $serialized_fields = variable_get($delta . '_fields', FALSE);
      $block_fields = $serialized_fields ? unserialize($serialized_fields) : wunderground_weather_current_fields();
      $i = 0;
      foreach (wunderground_weather_current_fields() as $key => $value) {
        $form['draggable']['fields'][$key] = array(
          'name' => array(
            '#markup' => check_plain($value),
          ),
          'enabled' => array(
            '#type' => 'checkbox',
            '#default_value' => isset($block_fields[$key]['#enabled']) ? $block_fields[$key]['#enabled'] : TRUE,
          ),
          'weight' => array(
            '#type' => 'weight',
            '#title' => t('Weight'),
            '#default_value' => isset($block_fields[$key]['#weight']) ? $block_fields[$key]['#weight'] : $i,
            '#delta' => 6,
            '#title_display' => 'invisible',
          ),
          '#weight' => isset($block_fields[$key]['#weight']) ? $block_fields[$key]['#weight'] : $i,
        );
        ++$i;
      }
      $form['icons'] = array(
        '#type' => 'fieldset',
        '#title' => t('Icons'),
      );
      $alphas = range('a', 'k');
      foreach ($alphas as $letter) {
        $icon_options[$letter] = _wunderground_weather_get_icons_sample($letter);
      }
      $form['icons']['wunderground_weather_current_icons_' . $t] = array(
        '#type' => 'radios',
        '#title' => t('Select the icon set you want to use.'),
        '#options' => $icon_options,
        '#default_value' => variable_get('wunderground_weather_current_icons_' . $t, 'a'),
      );
    }
  }
  return $form;
}