function date_locale_format_form in Date 6.2
Display list of enabled languages to configure date formats for.
1 string reference to 'date_locale_format_form'
- date_locale_menu in date_locale/
date_locale.module - Implementation of hook_menu().
File
- date_locale/
date_locale.module, line 119 - Enable different locales to have their own date formats.
Code
function date_locale_format_form($form_state) {
$form = array();
if (!isset($form_state['values'])) {
$step = 'languages';
}
else {
$step = 'config';
}
$form['step'] = array(
'#type' => 'value',
'#value' => $step,
);
// Form part 1: show language selection.
if ($step == 'languages') {
// Get list of languages.
$languages = locale_language_list('native');
// If site_country module is enabled, add country specific languages to
// languages array.
if (module_exists('site_country')) {
$country_code = variable_get('site_country_default_country', '');
if (!empty($country_code)) {
foreach ($languages as $langcode => $name) {
$country_language = $langcode . '-' . $country_code;
if (drupal_strlen($langcode) == 2 && !in_array($country_language, array_keys($languages))) {
$languages[$country_language] = "{$name} ({$country_code})";
}
}
}
}
$form['langcode'] = array(
'#title' => t('Language'),
'#type' => 'select',
'#options' => $languages,
'#multiple' => FALSE,
);
$form['buttons']['submit'] = array(
'#type' => 'submit',
'#value' => t('Search'),
'#submit' => array(
'date_locale_format_form_language_submit',
),
);
}
else {
// Add Drupal core's system.js and js settings.
date_api_add_system_javascript();
$languages = locale_language_list('native');
$langcode = $form_state['values']['langcode'];
$language_name = $languages[$langcode];
// Display the current language name.
$form['language_information'] = array(
'#value' => t('Date format settings for %language_name', array(
'%language_name' => $language_name,
)),
'#prefix' => '<p style="font-size: 1.2em;">',
'#suffix' => '</p>',
);
// Get list of date format types.
$types = date_get_format_types();
// Get list of available formats.
$formats = date_get_formats();
$choices = array();
foreach ($formats as $type => $list) {
foreach ($list as $f => $format) {
$choices[$f] = date_format_date(date_now(), 'custom', $f);
}
}
// Get configured formats for each language.
$locale_formats = 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, array_shift(array_keys($formats)));
}
include_once './' . drupal_get_path('module', 'date_api') . '/date_api.admin.inc';
date_api_date_format_select_field($form, $type, $type_info, $default, $choices);
}
$form['buttons']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#submit' => array(
'date_locale_format_form_formats_submit',
),
);
$form['buttons']['cancel'] = array(
'#type' => 'submit',
'#value' => t('Cancel'),
'#submit' => array(
'date_locale_format_form_formats_cancel',
),
);
}
return $form;
}