You are here

function clock_block_configure in Clock 7

Same name and namespace in other branches
  1. 7.2 clock.module \clock_block_configure()

Implement hook_block_configure().

File

./clock.module, line 61

Code

function clock_block_configure($delta = '') {
  if ($delta == 'clock') {

    // Time zone options.
    $time_zone = variable_get('clock_time_zone', 2);

    // If the time zone is not set to the integer values 1, 2 or 3 corresponding
    // to 'Site time zone', 'User time zone' and 'Local time zone' it contains
    // the name of a custom time zone, so the time zone type must be set to
    // integer value 4.
    $time_zone_type = $time_zone == 1 || $time_zone == 2 || $time_zone == 3 ? $time_zone : 4;
    $custom_time_zone = $time_zone_type == 4 ? $time_zone : 'UTC';
    $form['time_zone_type'] = array(
      '#type' => 'radios',
      '#title' => t('Time zone settings'),
      '#description' => t('<em>Local time zone</em> is the time zone on the operating system of the person visiting (regardless of anonymous or authenticated).'),
      '#options' => array(
        1 => t('Site time zone'),
        3 => t('Local time zone'),
        4 => t('Custom time zone'),
      ),
      '#default_value' => $time_zone_type,
    );

    // In case of user-configurable timezones show it as an option.
    if (variable_get('configurable_timezones', 1) == 1) {
      $form['time_zone_type']['#options'][2] = t('User time zone');
      $form['time_zone_type']['#description'] = t('<em>User time zone</em> is the time zone the Drupal user has selected on his or her profile page. <em>Local time zone</em> is the time zone on the operating system of the person visiting (regardless of anonymous or authenticated).');

      // Make the "User time zone" option appear second.
      ksort($form['time_zone_type']['#options']);
    }

    // date_timezone_names() returns an empty first row.
    $time_zone_names = date_timezone_names();
    array_shift($time_zone_names);
    $form['time_zone_custom'] = array(
      '#type' => 'select',
      '#options' => $time_zone_names,
      '#default_value' => $custom_time_zone,
      // Show the select list only if "Custom time zone" is selected.
      '#states' => array(
        'visible' => array(
          ':input[name="time_zone_type"]' => array(
            'value' => "4",
          ),
        ),
      ),
    );

    // Date type options.
    // Format the current time with each date type for display in the form. If
    // the user has changed the time zone since the last page load,
    // the formatted time is displayed in the wrong, old time zone.
    $date_types = array();
    foreach (system_get_date_types() as $date_type => $info) {
      $date_format = _clock_get_date_format($date_type);
      $date_types[$date_type] = $info['title'] . ' (' . date_format_date(date_now(_clock_get_timezone(TRUE)), 'custom', $date_format) . ')';
    }
    $form['date_type'] = array(
      '#type' => 'radios',
      '#title' => t('Date type'),
      '#description' => t('You can configure these date types on the <a href="@date-and-time-admin">date and time configuration page</a>.', array(
        '@date-and-time-admin' => url('admin/config/regional/date-time'),
      )),
      '#weight' => 3,
      '#default_value' => variable_get('clock_date_type', 'long'),
      '#options' => $date_types,
    );

    // Update options.
    $form['update'] = array(
      '#type' => 'checkbox',
      '#title' => t('Update the clock every second'),
      '#description' => t('This only works with JavaScript enabled.'),
      '#weight' => 5,
      '#default_value' => variable_get('clock_update', '1'),
    );
    return $form;
  }
}