system_date_format_save

Versions
7
system_date_format_save($date_format, $dfid = 0)

Save a date format to the database.

Parameters

$date_format An array of attributes for a date format.

$dfid If set, replace an existing date format with a new string using this identifier.

▾ 2 functions call system_date_format_save()

system_add_date_formats_form_submit in modules/system/system.admin.inc
Process new date format string submission.
system_date_formats_rebuild in modules/system/system.module
Resets the database cache of date formats and saves all new formats.

Code

modules/system/system.module, line 3481

<?php
function system_date_format_save($date_format, $dfid = 0) {
  $format = array();
  $format['dfid'] = $dfid;
  $format['type'] = $date_format['type'];
  $format['format'] = $date_format['format'];
  $format['locked'] = $date_format['locked'];

  // Update date_format table.
  if (!empty($date_format['is_new'])) {
    drupal_write_record('date_formats', $format);
  }
  else {
    $keys = ($dfid ? array('dfid') : array('format', 'type'));
    drupal_write_record('date_formats', $format, $keys);
  }

  $languages = language_list('enabled');
  $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 (in_array($langcode, $languages)) {
        $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);
        }
      }
    }
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.