function locale_date_format_form

Provide date localization configuration options to users.

1 string reference to 'locale_date_format_form'
locale_menu in modules/locale/locale.module
Implements hook_menu().

File

modules/locale/locale.admin.inc, line 1333

Code

function locale_date_format_form($form, &$form_state, $langcode) {
    $languages = locale_language_list('native');
    $language_name = $languages[$langcode];
    // Display the current language name.
    $form['language'] = array(
        '#type' => 'item',
        '#title' => t('Language'),
        '#markup' => check_plain($language_name),
        '#weight' => -10,
    );
    $form['langcode'] = array(
        '#type' => 'value',
        '#value' => $langcode,
    );
    // Get list of date format types.
    $types = system_get_date_types();
    // Get list of available formats.
    $formats = system_get_date_formats();
    $choices = array();
    foreach ($formats as $type => $list) {
        foreach ($list as $f => $format) {
            $choices[$f] = format_date(REQUEST_TIME, 'custom', $f);
        }
    }
    reset($formats);
    // Get configured formats for each language.
    $locale_formats = system_date_format_locale($langcode);
    // Display a form field for each format type.
    foreach ($types as $type => $type_info) {
        if (!empty($locale_formats) && in_array($type, array_keys($locale_formats))) {
            $default = $locale_formats[$type];
        }
        else {
            $default = variable_get('date_format_' . $type, key($formats));
        }
        // Show date format select list.
        $form['date_formats']['date_format_' . $type] = array(
            '#type' => 'select',
            '#title' => check_plain($type_info['title']),
            '#attributes' => array(
                'class' => array(
                    'date-format',
                ),
            ),
            '#default_value' => isset($choices[$default]) ? $default : 'custom',
            '#options' => $choices,
        );
    }
    $form['actions'] = array(
        '#type' => 'actions',
    );
    $form['actions']['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Save configuration'),
    );
    return $form;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.