function system_date_format_save

7.x system.module 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

system_get_date_types()

http://php.net/date

3 calls to system_date_format_save()
DateTimeFunctionalTest::testDateFormatStorage in drupal-7.x/modules/system/system.test
Test if the date formats are stored properly.
system_add_date_formats_form_submit in drupal-7.x/modules/system/system.admin.inc
Process new date format string submission.
system_date_formats_rebuild in drupal-7.x/modules/system/system.module
Resets the database cache of date formats and saves all new date formats.

File

drupal-7.x/modules/system/system.module, line 3879
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);
        }
      }
    }
  }
}