function _date_formats_build in Date 6.2
Builds and returns the list of available date formats.
Return value
Array of date formats.
2 calls to _date_formats_build()
- date_formats_rebuild in ./
date_api.module - Resets the database cache of date formats, and saves all new date formats to the database.
- date_get_formats in ./
date_api.module - Get the list of date formats for a particular format length.
File
- ./
date_api.module, line 2130 - 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_formats_build() {
$date_formats = array();
// Prevent errors in the upgrade before the date_format table exists.
if (defined('MAINTENANCE_MODE') && !db_table_exists('date_format')) {
return $date_formats;
}
// First handle hook_date_format_types().
$types = _date_format_types_build();
foreach ($types as $type => $info) {
date_format_type_save($info);
}
// Get formats supplied by various contrib modules.
$module_formats = module_invoke_all('date_formats');
foreach ($module_formats as $module_format) {
$module_format['locked'] = 1;
// System types are locked.
// If no format type is specified, assign 'custom'.
if (!isset($module_format['type'])) {
$module_format['type'] = 'custom';
}
if (!in_array($module_format['type'], array_keys($types))) {
continue;
}
if (!isset($date_formats[$module_format['type']])) {
$date_formats[$module_format['type']] = array();
}
// If another module already set this format, merge in the new settings.
if (isset($date_formats[$module_format['type']][$module_format['format']])) {
$date_formats[$module_format['type']][$module_format['format']] = array_merge_recursive($date_formats[$module_format['type']][$module_format['format']], $format);
}
else {
// This setting will be overridden later if it already exists in the db.
$module_format['is_new'] = TRUE;
$date_formats[$module_format['type']][$module_format['format']] = $module_format;
}
}
// Get custom formats added to the database by the end user.
$result = db_query('SELECT df.dfid, df.format, df.type, df.locked, dfl.language FROM {date_formats} df LEFT JOIN {date_format_types} dft ON df.type = dft.type LEFT JOIN {date_format_locale} dfl ON df.format = dfl.format AND df.type = dfl.type ORDER BY df.type, df.format');
while ($object = db_fetch_object($result)) {
// If this format type isn't set, initialise the array.
if (!isset($date_formats[$object->type])) {
$date_formats[$object->type] = array();
}
// If this format not already present, add it to the array.
if (!isset($date_formats[$object->type][$object->format])) {
// We don't set 'is_new' as it is already in the db.
$format = array();
$format['module'] = '';
$format['dfid'] = $object->dfid;
$format['format'] = $object->format;
$format['type'] = $object->type;
$format['locked'] = $object->locked;
$format['locales'] = array(
$object->language,
);
$date_formats[$object->type][$object->format] = $format;
}
else {
$format = array();
$format['is_new'] = FALSE;
// It's in the db, so override this setting.
$format['dfid'] = $object->dfid;
$format['format'] = $object->format;
$format['type'] = $object->type;
$format['locked'] = $object->locked;
if (!empty($object->language)) {
$format['locales'] = array_merge($date_formats[$object->type][$object->format]['locales'], array(
$object->language,
));
}
$date_formats[$object->type][$object->format] = array_merge($date_formats[$object->type][$object->format], $format);
}
}
// Allow other modules to modify these formats.
drupal_alter('date_formats', $date_formats);
return $date_formats;
}