You are here

function date_api_date_format_form_elements in Date 6.2

Add drop down selects for date format types.

Parameters

&$form: The form being altered.

1 call to date_api_date_format_form_elements()
date_api_date_formats_form in ./date_api.admin.inc
Allow users to configure additional date format types.

File

./date_api.admin.inc, line 85
Administrative page callbacks for the date_api module.

Code

function date_api_date_format_form_elements(&$form) {
  $form['date_formats'] = array(
    '#type' => 'fieldset',
    '#title' => t('Date formats'),
  );

  // Get list of all available date format types.
  $format_types = date_get_format_types('', TRUE);

  // Get list of all available date formats.
  $all_formats = array();
  $date_formats = date_get_formats('', TRUE);

  // Call this to rebuild the list, and to have default list.
  foreach ($date_formats as $type => $format_info) {
    $all_formats = array_merge($all_formats, $format_info);
  }
  $custom_formats = date_get_formats('custom');
  foreach ($format_types as $type => $type_info) {

    // If a system type, only show the available formats for that type and
    // custom ones.
    if ($type_info['locked'] == 1) {
      $formats = date_get_formats($type);
      if (empty($formats)) {
        $formats = $all_formats;
      }
      elseif (!empty($custom_formats)) {
        $formats = array_merge($formats, $custom_formats);
      }
    }
    else {
      $formats = $all_formats;
    }
    $choices = array();
    foreach ($formats as $f => $format) {
      $choices[$f] = date_format_date(date_now(), 'custom', $f);
    }
    $keys = array_keys($formats);
    $default = variable_get('date_format_' . $type, array_shift($keys));

    // Get format type info for this format type.
    $type_info = date_get_format_types($type);
    date_api_date_format_select_field($form, $type, $type_info, $default, $choices, 1);
  }
}