On this page
function system_date_format_save
system_date_format_save($date_format, $dfid = 0)
Saves a date format to the database.
Parameters
$date_format: A date format array containing the following keys:
- type: The name of the date type this format is associated with.
- format: The PHP date format string.
- locked: A boolean indicating whether or not this format should be configurable from the user interface.
$dfid: If set, replace the existing date format having this ID with the information specified in $date_format.
See also
File
- modules/system/system.module, line 3913
- Configuration system that lets administrators modify the workings of the site.
Code
function system_date_format_save($date_format, $dfid = 0) {
$info = array();
$info['dfid'] = $dfid;
$info['type'] = $date_format['type'];
$info['format'] = $date_format['format'];
$info['locked'] = $date_format['locked'];
// Update date_format table.
if (!empty($date_format['is_new'])) {
drupal_write_record('date_formats', $info);
}
else {
$keys = ($dfid ? array('dfid') : array('format', 'type'));
drupal_write_record('date_formats', $info, $keys);
}
// Retrieve an array of language objects for enabled languages.
$languages = language_list('enabled');
// This list is keyed off the value of $language->enabled; we want the ones
// that are enabled (value of 1).
$languages = $languages[1];
$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 (isset($languages[$langcode])) {
$is_existing = (bool) db_query_range('SELECT 1 FROM {date_format_locale} WHERE type = :type AND language = :language', 0, 1, array(':type' => $date_format['type'], ':language' => $langcode))->fetchField();
if (!$is_existing) {
$locale_format['language'] = $langcode;
drupal_write_record('date_format_locale', $locale_format);
}
}
}
}
}
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/modules!system!system.module/function/system_date_format_save/7.x