function date_format_save in Date 6.2
Save a date format to the database.
Parameters
$date_format: An array of attributes for a date format.
2 calls to date_format_save()
- date_api_date_time_settings_submit in ./
date_api.admin.inc - date_formats_rebuild in ./
date_api.module - Resets the database cache of date formats, and saves all new date formats to the database.
File
- ./
date_api.module, line 2009 - This module will make the date API available to other modules. Designed to provide a light but flexible assortment of functions and constants, with more functionality in additional files that are not loaded unless other modules specifically include them.
Code
function date_format_save($date_format) {
$format = array();
$format['type'] = $date_format['type'];
$format['format'] = $date_format['format'];
$format['locked'] = $date_format['locked'];
// Update date_format table.
if (isset($date_format['is_new']) && !empty($date_format['is_new'])) {
drupal_write_record('date_formats', $format);
}
else {
drupal_write_record('date_formats', $format, array(
'format',
'type',
));
}
$languages = language_list('enabled');
$languages = $languages[1];
// 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 => $details) {
$country_language = $langcode . '-' . $country_code;
if (drupal_strlen($langcode) == 2 && !in_array($country_language, array_keys($languages))) {
$name = $details->name;
$languages[$country_language] = "{$name} ({$country_code})";
}
}
}
}
$locale_format = array();
$locale_format['type'] = $date_format['type'];
$locale_format['format'] = $date_format['format'];
// Check if the suggested language codes are configured and enabled.
if (!empty($date_format['locales'])) {
foreach ($date_format['locales'] as $langcode) {
// Only proceed if language is enabled.
if (in_array($langcode, $languages)) {
$is_existing = db_result(db_query("SELECT COUNT(*) FROM {date_format_locale} WHERE type = '%s' AND language = '%s'", $date_format['type'], $langcode));
if (!$is_existing) {
$locale_format['language'] = $langcode;
drupal_write_record('date_format_locale', $locale_format);
}
}
}
}
}