diff --git a/core/modules/locale/locale.install b/core/modules/locale/locale.install index af08d52..c527cca 100644 --- a/core/modules/locale/locale.install +++ b/core/modules/locale/locale.install @@ -944,22 +944,14 @@ function locale_update_8015() { * Converts localized date formats. */ function locale_update_8016() { - $configs = array(); - // Fetch all date types from {date_format_type}. $result = db_query('SELECT * FROM {date_format_locale}'); foreach ($result as $format) { $language = $format->language; // Create config objects for the language if not yet done. - if (!isset($configs[$language])) { - $configs[$language] = config('locale.config.' . $language . '.system.date'); - } - $configs[$language]->set('formats.' . $format->type . '.pattern.php', $format->format); - } - - // Save all instantiated config objects. - foreach ($configs as $config) { - $config->save(); + config("locale.config.$language.system.date_format." . $format->type) + ->set('pattern.php', $format->format) + ->save(); } } diff --git a/core/modules/system/lib/Drupal/system/DateFormatInterface.php b/core/modules/system/lib/Drupal/system/DateFormatInterface.php index fc53d8d..ae35fae 100644 --- a/core/modules/system/lib/Drupal/system/DateFormatInterface.php +++ b/core/modules/system/lib/Drupal/system/DateFormatInterface.php @@ -49,4 +49,9 @@ public function setLocales(array $locales); */ public function getLocales(); + /** + * @return bool + */ + public function hasLocales(); + } diff --git a/core/modules/system/lib/Drupal/system/Form/DateFormatLocalizeResetForm.php b/core/modules/system/lib/Drupal/system/Form/DateFormatLocalizeResetForm.php index a3576c5..cb58c3f 100644 --- a/core/modules/system/lib/Drupal/system/Form/DateFormatLocalizeResetForm.php +++ b/core/modules/system/lib/Drupal/system/Form/DateFormatLocalizeResetForm.php @@ -101,7 +101,9 @@ public function buildForm(array $form, array &$form_state, $langcode = NULL) { * {@inheritdoc} */ public function submitForm(array &$form, array &$form_state) { - $this->configFactory->get('locale.config.' . $this->language->langcode . '.system.date')->delete(); + foreach (config_get_storage_names_with_prefix('locale.config.' . $this->language->langcode . '.system.date_format') as $config_id) { + $this->configFactory->get($config_id)->delete(); + } $form_state['redirect'] = 'admin/config/regional/date-time/locale'; } diff --git a/core/modules/system/lib/Drupal/system/Plugin/Core/Entity/DateFormat.php b/core/modules/system/lib/Drupal/system/Plugin/Core/Entity/DateFormat.php index 2f30fae..7cb8a3f 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/Core/Entity/DateFormat.php +++ b/core/modules/system/lib/Drupal/system/Plugin/Core/Entity/DateFormat.php @@ -140,6 +140,13 @@ public function setLocales(array $locales) { /** * {@inheritdoc} */ + public function hasLocales() { + return !empty($this->locales); + } + + /** + * {@inheritdoc} + */ public function addLocale($locale) { $this->locales[] = $locale; $this->locales = array_unique($this->locales); diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/DateUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/DateUpgradePathTest.php index ce48a3d..990cbd5 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/DateUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/DateUpgradePathTest.php @@ -91,10 +91,10 @@ public function testDateUpgrade() { ), ); - $config = config('locale.config.de.system.date'); foreach ($expected_de_formats as $locale_format) { - $format = $config->get('formats.' . $locale_format['type'] . '.pattern.php'); + $format = config('locale.config.de.system.date_format.' . $locale_format['type'])->get('pattern.php'); $this->assertEqual($locale_format['format'], $format); } } + } diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc index c55b0f6..4dd7e5e 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -5,6 +5,7 @@ * Admin page callbacks for the system module. */ +use Drupal\system\DateFormatInterface; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Drupal\system\Form\ModulesInstallConfirmForm; @@ -1824,21 +1825,16 @@ function system_date_format_localize_form($form, &$form_state, $langcode) { $choices = array(); foreach ($formats as $date_format_id => $format_info) { // Ignore values that are localized. - if (empty($format_info->locales)) { + if (!$format_info->hasLocales()) { $choices[$date_format_id] = format_date(REQUEST_TIME, $date_format_id); } - else { - unset($formats[$date_format_id]); - } } // Get configured formats for each language. - $locale_formats = system_date_format_locale($langcode); - if (!empty($locale_formats)) { - $formats += $locale_formats; - foreach ($locale_formats as $date_format_id => $format_info) { - $choices[$date_format_id] = format_date(REQUEST_TIME, $date_format_id); - } + $config_prefix = 'locale.config.' . $langcode . '.system.date_format'; + foreach (config_get_storage_names_with_prefix($config_prefix) as $config_id) { + $date_format_id = substr($config_id, strlen($config_prefix. '.')); + $choices[$date_format_id] = format_date(REQUEST_TIME, $date_format_id); } // Display a form field for each format type. @@ -1872,7 +1868,7 @@ function system_date_format_localize_form_submit($form, &$form_state) { foreach ($formats as $date_format_id => $format_info) { if (isset($form_state['values']['date_format_' . $date_format_id])) { $format = $form_state['values']['date_format_' . $date_format_id]; - system_date_format_localize_form_save($langcode, $date_format_id, $formats[$format]->get('pattern')); + system_date_format_localize_form_save($langcode, $format_info, $formats[$format]->get('pattern')); } } drupal_set_message(t('Configuration saved.')); @@ -1913,16 +1909,17 @@ function theme_system_date_format_localize_form($variables) { /** * Save locale specific date formats to the database. * - * @param $langcode + * @param string $langcode * Language code, can be 2 characters, e.g. 'en' or 5 characters, e.g. * 'en-CA'. - * @param $date_format_id - * Date format id, e.g. 'short', 'medium'. - * @param $format + * @param \Drupal\system\DateFormatInterface $date_format + * The date format entity. + * @param string $format * The date format string. */ -function system_date_format_localize_form_save($langcode, $date_format_id, $format) { - config('locale.config.' . $langcode . '.system.date') - ->set('formats.' . $date_format_id . '.pattern', $format) +function system_date_format_localize_form_save($langcode, DateFormatInterface $date_format, $format) { + $date_format->addLocale($langcode)->save(); + config('locale.config.' . $langcode . '.system.date_format.' . $date_format->id()) + ->set('pattern', $format) ->save(); } diff --git a/core/modules/system/system.module b/core/modules/system/system.module index f457656..9b2be4c 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -3656,39 +3656,6 @@ function system_run_automated_cron() { } /** - * Gets the appropriate date format string for a date type and locale. - * - * @param $langcode - * (optional) String language code for the current locale. This can be a 2 character - * language code like 'en' and 'fr' or a 5 character language code like - * 'en-gb' and 'en-us'. - * @param $date_format_id - * (optional) String machine name for the date format. - * - * @return - * If $date_format_id and $langcode are specified, returns the corresponding - * date format string. If only $langcode is specified, returns an array of - * all date format strings for that locale, keyed by the date type. If - * neither is specified returns FALSE. - */ -function system_date_format_locale($langcode = NULL, $date_format_id = NULL) { - $formats = &drupal_static(__FUNCTION__); - - if (!isset($formats[$langcode])) { - $formats[$langcode] = config('locale.config.' . $langcode . '.system.date')->get('formats'); - } - - if ($date_format_id && $langcode && !empty($formats[$langcode][$date_format_id])) { - return $formats[$langcode][$date_format_id]; - } - elseif ($langcode && !empty($formats[$langcode])) { - return $formats[$langcode]; - } - - return FALSE; -} - -/** * Returns HTML for a confirmation form. * * By default this does not alter the appearance of a form at all,