1 system.module system_date_format_save($date_format)

Saves a date format to the database.

Parameters

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

  • name: The machine name of this date format.
  • label: The human-readable label for this date format.
  • pattern: The pattern string as usable by the PHP date() function.
  • langcode: Optional. If multiple languages are available, this specifies which language the default format is in.
  • module: If provided by a module, the name of the providing module. This will prevent the format from being deleted in the UI.
  • hidden: Optional. A boolean indicating whether or not this format should be configurable from the user interface.

See also

http://php.net/date

File

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

Code

function system_date_format_save($date_format) {
  $format = array(
    'label' => $date_format['label'],
    'pattern' => $date_format['pattern'],
  );
  // Trim empty strings from locale settings.
  if (isset($date_format['locales'])) {
    $date_format['locales'] = array_filter(array_filter($date_format['locales'], 'trim'));
  }
  // Don't save empty defaults.
  foreach (array('module', 'hidden', 'locales') as $key) {
    if (!empty($date_format[$key])) {
      $format[$key] = $date_format[$key];
    }
  }
  config_set('system.date', 'formats.' . $date_format['name'], $format);
  backdrop_static_reset('system_get_date_formats');
}