diff --git a/core/includes/common.inc b/core/includes/common.inc index 838f228..8e568e6 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -1906,11 +1906,8 @@ function format_date($timestamp, $type = 'medium', $format = '', $timezone = NUL switch ($type) { case 'short': - $format = variable_get('date_format_short', 'm/d/Y - H:i'); - break; - case 'long': - $format = variable_get('date_format_long', 'l, F j, Y - H:i'); + $format = config('system.date_time')->get('format' . $type); break; case 'html_datetime': @@ -1949,11 +1946,11 @@ function format_date($timestamp, $type = 'medium', $format = '', $timezone = NUL default: // Retrieve the format of the custom $type passed. if ($type != 'medium') { - $format = variable_get('date_format_' . $type, ''); + $format = config('system.date_time')->get('format' . $type); } // Fall back to 'medium'. - if ($format === '') { - $format = variable_get('date_format_medium', 'D, m/d/Y - H:i'); + if (empty($format)) { + $format = config('system.date_time')->get('format.medium'); } break; } diff --git a/core/includes/form.inc b/core/includes/form.inc index 0c9cd5d..54aa86c 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -2939,7 +2939,7 @@ function form_process_date($element) { $element['#tree'] = TRUE; // Determine the order of day, month, year in the site's chosen date format. - $format = variable_get('date_format_short', 'm/d/Y - H:i'); + $format = config('system.date_time')->get('format.short'); $sort = array(); $sort['day'] = max(strpos($format, 'd'), strpos($format, 'j')); $sort['month'] = max(strpos($format, 'm'), strpos($format, 'M')); diff --git a/core/modules/aggregator/aggregator.pages.inc b/core/modules/aggregator/aggregator.pages.inc index 78ca5bc..52155e0 100644 --- a/core/modules/aggregator/aggregator.pages.inc +++ b/core/modules/aggregator/aggregator.pages.inc @@ -335,7 +335,7 @@ function template_preprocess_aggregator_item(&$variables) { $variables['source_date'] = t('%ago ago', array('%ago' => format_interval(REQUEST_TIME - $item->timestamp))); } else { - $variables['source_date'] = format_date($item->timestamp, 'custom', variable_get('date_format_medium', 'D, m/d/Y - H:i')); + $variables['source_date'] = format_date($item->timestamp, 'custom', config('system.date_time')->get('format.medium')); } $variables['categories'] = array(); diff --git a/core/modules/system/config/system.date_time.yml b/core/modules/system/config/system.date_time.yml new file mode 100644 index 0000000..7869508 --- /dev/null +++ b/core/modules/system/config/system.date_time.yml @@ -0,0 +1,4 @@ +format: + long: 'l, F j, Y - H:i' + medium: 'D, m/d/Y - H:i' + short: 'm/d/Y - H:i' diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/FormatDateTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/FormatDateTest.php index 7a71d33..226f41b 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/FormatDateTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Common/FormatDateTest.php @@ -30,9 +30,11 @@ class FormatDateTest extends WebTestBase { function setUp() { parent::setUp('language'); variable_set('configurable_timezones', 1); - variable_set('date_format_long', 'l, j. F Y - G:i'); - variable_set('date_format_medium', 'j. F Y - G:i'); - variable_set('date_format_short', 'Y M j - g:ia'); + $config = config('system.date_time') + ->set('format.long', 'l, j. F Y - G:i') + ->set('format.medium', 'j. F Y - G:i') + ->set('format.short', 'Y M j - g:ia') + ->save(); variable_set('locale_custom_strings_' . self::LANGCODE, array( '' => array('Sunday' => 'domingo'), 'Long month name' => array('March' => 'marzo'), diff --git a/core/modules/system/lib/Drupal/system/Tests/System/DateTimeTest.php b/core/modules/system/lib/Drupal/system/Tests/System/DateTimeTest.php index 84bd7c6..b5a918e 100644 --- a/core/modules/system/lib/Drupal/system/Tests/System/DateTimeTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/System/DateTimeTest.php @@ -37,8 +37,9 @@ class DateTimeTest extends WebTestBase { // Setup date/time settings for Honolulu time. variable_set('date_default_timezone', 'Pacific/Honolulu'); variable_set('configurable_timezones', 0); - variable_set('date_format_medium', 'Y-m-d H:i:s O'); - + config('system.date_time') + ->set('format.medium', 'Y-m-d H:i:s O') + ->save(); // Create some nodes with different authored-on dates. $date1 = '2007-01-31 21:00:00 -1000'; $date2 = '2007-07-31 21:00:00 -1000'; diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc index 2947245..d919d57 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -2026,13 +2026,13 @@ function system_regional_settings() { * Form builder; Configure the site date and time settings. * * @ingroup forms - * @see system_settings_form() + * @see system_date_time_settings_submit(). */ -function system_date_time_settings() { +function system_date_time_settings($form, $form_state) { // Get list of all available date types. drupal_static_reset('system_get_date_types'); $format_types = system_get_date_types(); - + $config = config('system.date_time'); // Get list of all available date formats. $all_formats = array(); drupal_static_reset('system_get_date_formats'); @@ -2064,7 +2064,7 @@ function system_date_time_settings() { $choices[$f] = format_date(REQUEST_TIME, 'custom', $f); } reset($formats); - $default = variable_get('date_format_' . $type, key($formats)); + $default = $config->get('format' . $type); // Get date type info for this date type. $type_info = system_get_date_types($type); @@ -2094,7 +2094,22 @@ function system_date_time_settings() { // Display a message if no date types configured. $form['#empty_text'] = t('No date types available. Add date type.', array('@link' => url('admin/config/regional/date-time/types/add'))); - return system_settings_form($form); + return system_config_form($form, $form_state); +} + +/** + * Form submission handler for system_date_time_settings(). + */ +function system_date_time_settings_submit($form, $form_state) { + $config = config('system.date_time'); + foreach ($form_state['values'] as $key => $value) { + $pos = strpos($key, 'date_format_'); + if ($pos !== FALSE) { + $format = substr($key, 12); + $config->set('format' . $type, $value); + } + } + $config->save(); } /** @@ -2215,7 +2230,9 @@ function system_add_date_format_type_form_submit($form, &$form_state) { $format_type['locked'] = 0; $format_type['is_new'] = 1; system_date_format_type_save($format_type); - variable_set('date_format_' . $machine_name, $form_state['values']['date_format']); + config('system.date_time') + ->set('format' . $machine_name, $form_state['values']['date_format']) + ->save(); drupal_set_message(t('New date type added successfully.')); $form_state['redirect'] = 'admin/config/regional/date-time'; @@ -3249,7 +3266,7 @@ function system_date_format_localize_form($form, &$form_state, $langcode) { $default = $locale_formats[$type]; } else { - $default = variable_get('date_format_' . $type, key($formats)); + $default = config('system.date_time')->get('format' . $type); } // Show date format select list. diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index 3d2cae0..212d66b 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -3516,7 +3516,7 @@ function hook_archiver_info_alter(&$info) { * * To define a date type in a module and make sure a format has been assigned to * it, without requiring a user to visit the administrative interface, use - * @code variable_set('date_format_' . $type, $format); @endcode + * @code config('system.date_time')->set('format' . $type, $format); @endcode * where $type is the machine-readable name defined here, and $format is a PHP * date format string. * @@ -3586,7 +3586,7 @@ function hook_date_format_types_alter(&$types) { * initialization chooses a locale-specific format for the three core-provided * types (see system_get_localized_date_format() for details). If your module * needs to ensure that a date type it defines has a format associated with it, - * call @code variable_set('date_format_' . $type, $format); @endcode + * call @code config('system.date_time')->set('format' . $type, $format); @endcode * where $type is the machine-readable name defined in hook_date_format_types(), * and $format is a PHP date format string. * diff --git a/core/modules/system/system.install b/core/modules/system/system.install index 96c02c3..202f057 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -1973,6 +1973,8 @@ function system_update_8013() { /** * Moves system logging settings from variables to config. + * + * @ingroup config_upgrade */ function system_update_8014() { $error_level = db_query("SELECT value FROM {variable} WHERE name = 'error_level'")->fetchField(); @@ -1998,6 +2000,20 @@ function system_update_8014() { } /** + * Moves systems date format settings from variables to config. + * + * @ingroup config_upgrade + */ +function system_update_8015() { + $format_types = system_get_date_types(); + $variables = array(); + foreach ($format_types as $type => $format_type) { + $variables['date_format_' . $type] = 'format' . $type; + } + update_variables_to_config('system.date_time', $variables); +} + +/** * @} End of "defgroup updates-7.x-to-8.x". * The next series of updates should start at 9000. */ diff --git a/core/modules/system/system.module b/core/modules/system/system.module index a530c30..3c9e4b5 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -2080,7 +2080,9 @@ function system_init() { // Setup appropriate date formats for this locale. $formats = system_get_localized_date_format($languages); foreach ($formats as $format_type => $format) { - $conf[$format_type] = $format; + $pos = strpos($format_type, 'date_format_'); + $format_type = substr($format_type, 12); + $conf['system.date_time']['format'][$format_type] = $format; } } @@ -2130,10 +2132,10 @@ function system_init() { */ function system_get_localized_date_format($languages) { $formats = array(); - + $config = config('system.date_time'); // Get list of different format types. $format_types = system_get_date_types(); - $short_default = variable_get('date_format_short', 'm/d/Y - H:i'); + $short_default = $config->get('format.short'); // Loop through each language until we find one with some date formats // configured. @@ -2150,7 +2152,8 @@ function system_get_localized_date_format($languages) { // Otherwise get default variable setting. If this is not set, default // to the short format. else { - $formats['date_format_' . $type] = variable_get('date_format_' . $type, $short_default); + $default = $config->get('format' . $type); + $formats['date_format_' . $type] = !empty($default) ? $default : $short_default; } } @@ -2163,14 +2166,15 @@ function system_get_localized_date_format($languages) { $system_types = array('short', 'medium', 'long'); // Handle system types separately as they have defaults if no variable exists. $formats['date_format_short'] = $short_default; - $formats['date_format_medium'] = variable_get('date_format_medium', 'D, m/d/Y - H:i'); - $formats['date_format_long'] = variable_get('date_format_long', 'l, F j, Y - H:i'); + $formats['date_format_medium'] = $config->get('format.medium'); + $formats['date_format_long'] = $config->get('format.long'); // For non-system types, get the default setting, otherwise use the short // format. foreach ($format_types as $type => $type_info) { if (!in_array($type, $system_types)) { - $formats['date_format_' . $type] = variable_get('date_format_' . $type, $short_default); + $default = $config->get('format' . $type); + $formats['date_format_' . $type] = !empty($default) ? $default : $short_default; } } @@ -3678,7 +3682,7 @@ function system_time_zones($blank = NULL) { // reasons and should not be used, the list is filtered by a regular // expression. if (preg_match('!^((Africa|America|Antarctica|Arctic|Asia|Atlantic|Australia|Europe|Indian|Pacific)/|UTC$)!', $zone)) { - $zones[$zone] = t('@zone: @date', array('@zone' => t(str_replace('_', ' ', $zone)), '@date' => format_date(REQUEST_TIME, 'custom', variable_get('date_format_long', 'l, F j, Y - H:i') . ' O', $zone))); + $zones[$zone] = t('@zone: @date', array('@zone' => t(str_replace('_', ' ', $zone)), '@date' => format_date(REQUEST_TIME, 'custom', config('system.date_time')->get('format.long') . ' O', $zone))); } } // Sort the translated time zones alphabetically. diff --git a/core/modules/user/lib/Drupal/user/Tests/UserTimeZoneTest.php b/core/modules/user/lib/Drupal/user/Tests/UserTimeZoneTest.php index 3ff4daf..de3ab04 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserTimeZoneTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserTimeZoneTest.php @@ -28,7 +28,9 @@ class UserTimeZoneTest extends WebTestBase { // Setup date/time settings for Los Angeles time. variable_set('date_default_timezone', 'America/Los_Angeles'); variable_set('configurable_timezones', 1); - variable_set('date_format_medium', 'Y-m-d H:i T'); + config('system.date_time') + ->set('format.medium', 'Y-m-d H:i T') + ->save(); // Create a user account and login. $web_user = $this->drupalCreateUser();