diff --git a/core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php b/core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php index 540da5598d..044353c0ae 100644 --- a/core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php +++ b/core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php @@ -199,11 +199,12 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#description' => $this->t('Select the default country for the site.'), '#weight' => 0, ]; + $default_timezone = $this->config('system.date')->get('timezone.default'); $form['regional_settings']['date_default_timezone'] = [ '#type' => 'select', '#title' => $this->t('Default time zone'), // Use system timezone if set, but avoid throwing a warning in PHP >=5.4 - '#default_value' => @date_default_timezone_get(), + '#default_value' => empty($default_timezone) ? @date_default_timezone_get() : $default_timezone, '#options' => system_time_zones(NULL, TRUE), '#description' => $this->t('By default, dates in this site will be displayed in the chosen time zone.'), '#weight' => 5, diff --git a/core/modules/system/src/Tests/Installer/InstallerSiteConfigDefaultTest.php b/core/modules/system/src/Tests/Installer/InstallerSiteConfigDefaultTest.php new file mode 100644 index 0000000000..1b2021ec6e --- /dev/null +++ b/core/modules/system/src/Tests/Installer/InstallerSiteConfigDefaultTest.php @@ -0,0 +1,21 @@ +assertEqual(\Drupal::config('system.date')->get('timezone.default'), @date_default_timezone_get()); + } + +} diff --git a/core/modules/system/src/Tests/Installer/InstallerSiteConfigProfileTest.php b/core/modules/system/src/Tests/Installer/InstallerSiteConfigProfileTest.php new file mode 100644 index 0000000000..588bd2e93f --- /dev/null +++ b/core/modules/system/src/Tests/Installer/InstallerSiteConfigProfileTest.php @@ -0,0 +1,43 @@ +assertEqual(\Drupal::config('system.site')->get('mail'), 'profile-testing-site-config@example.com'); + + // The install profile set the timezone to one of two possibilities, but + // never to the system timezone. + $timezone = \Drupal::config('system.date')->get('timezone.default'); + $this->assertNotEqual($timezone, @date_default_timezone_get()); + $this->assertTrue($timezone == 'America/Los_Angeles' || $timezone == 'America/New_York', 'Timezone is either Los Angeles or New York.'); + } + +} diff --git a/core/profiles/testing_site_config/testing_site_config.info.yml b/core/profiles/testing_site_config/testing_site_config.info.yml new file mode 100644 index 0000000000..31a390557e --- /dev/null +++ b/core/profiles/testing_site_config/testing_site_config.info.yml @@ -0,0 +1,6 @@ +name: Testing site config +type: profile +description: 'Minimal profile for testing with default site config.' +version: VERSION +core: 8.x +hidden: true diff --git a/core/profiles/testing_site_config/testing_site_config.install b/core/profiles/testing_site_config/testing_site_config.install new file mode 100644 index 0000000000..954e4a0b66 --- /dev/null +++ b/core/profiles/testing_site_config/testing_site_config.install @@ -0,0 +1,20 @@ +getEditable('system.site') + ->set('mail', 'profile-testing-site-config@example.com') + ->save(TRUE); + + // Set the time zone to something that is not the system timezone. + $timezone = 'America/Los_Angeles'; + if ($timezone == @date_default_timezone_get()) { + $timezone = 'America/New_York'; + } + \Drupal::configFactory()->getEditable('system.date') + ->set('timezone.default', $timezone) + ->save(TRUE); +}