function system_date_format_save

Saves a date format to the database.

Parameters

string $date_format_id: If set, replace the existing date format having this ID with the information specified in $format_info.

array $format_info: A date format array containing the following keys:

  • name: The string name of the date type this format is associated with.
  • pattern: An associative array keyed by 'php' and 'intl' with the PHP and/or IntlDateFormatter date format strings for each.
  • locked: A boolean indicating whether or not this format should be configurable from the user interface.

See also

http://php.net/date

2 calls to system_date_format_save()
DateTimeTest::testDateFormatStorage in drupal/core/modules/system/lib/Drupal/system/Tests/System/DateTimeTest.php
Test if the date formats are stored properly.
system_date_formats_form_submit in drupal/core/modules/system/system.admin.inc
Process date format string submission.

File

drupal/core/modules/system/system.module, line 3750
Configuration system that lets administrators modify the workings of the site.

Code

function system_date_format_save($date_format_id, $format_info) {
  config('system.date')
    ->set('formats.' . $date_format_id, $format_info)
    ->save();
  $languages = language_list();
  $locale_format = array(
    'name' => $format_info['name'],
    'pattern' => $format_info['pattern'],
  );

  // Check if the suggested language codes are configured.
  if (!empty($format_info['locales'])) {
    foreach ($format_info['locales'] as $langcode) {
      if (isset($languages[$langcode])) {
        config('locale.config.' . $langcode . '.system.date')
          ->set('formats.' . $date_format_id, $locale_format)
          ->save();
      }
    }
  }
}