diff --git a/core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php b/core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php index c28b7f8fd4..7ff231713e 100644 --- a/core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php +++ b/core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php @@ -152,10 +152,13 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#required' => TRUE, '#weight' => -20, ]; + // Use the default site mail if one is already configured, or fall back to + // PHP's configured sendmail_from. + $default_site_mail = $this->config('system.site')->get('mail') ?: ini_get('sendmail_from'); $form['site_information']['site_mail'] = [ '#type' => 'email', '#title' => $this->t('Site email address'), - '#default_value' => ini_get('sendmail_from'), + '#default_value' => $default_site_mail, '#description' => $this->t("Automated emails, such as registration information, will be sent from this address. Use an address ending in your site's domain to help prevent these emails from being flagged as spam."), '#required' => TRUE, '#weight' => -15, @@ -199,11 +202,14 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#description' => $this->t('Select the default country for the site.'), '#weight' => 0, ]; + // Use the default site timezone if one is already configured, or fall back + // to the system timezone if set (and avoid throwing a warning in + // PHP >=5.4). + $default_timezone = $this->config('system.date')->get('timezone.default') ?: @date_default_timezone_get(); $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' => $default_timezone, '#options' => system_time_zones(), '#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..1117bea095 --- /dev/null +++ b/core/modules/system/src/Tests/Installer/InstallerSiteConfigDefaultTest.php @@ -0,0 +1,33 @@ +assertFieldByName('site_mail', ini_get('sendmail_from')); + $this->assertFieldByName('date_default_timezone', @date_default_timezone_get()); + + return parent::setUpSite(); + } + + /** + * Verify the correct site config was set. + */ + public function testInstaller() { + $this->assertEqual(\Drupal::config('system.site')->get('mail'), $this->parameters['forms']['install_configure_form']['site_mail']); + $this->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..421cb48936 --- /dev/null +++ b/core/modules/system/src/Tests/Installer/InstallerSiteConfigProfileTest.php @@ -0,0 +1,61 @@ +profile_timezone = 'America/Los_Angeles'; + if ($this->profile_timezone == @date_default_timezone_get()) { + $this->profile_timezone = 'America/New_York'; + } + } + + /** + * {@inheritdoc} + */ + protected function installParameters() { + $parameters = parent::installParameters(); + + // Don't override the site email address, allowing it to default to the one + // from our install profile. + unset($parameters['forms']['install_configure_form']['site_mail']); + + return $parameters; + } + + /** + * {@inheritdoc} + */ + protected function setUpSite() { + $this->assertFieldByName('site_mail', $this->profile_site_mail); + $this->assertFieldByName('date_default_timezone', $this->profile_timezone); + + return parent::setUpSite(); + } + + /** + * Verify the correct site config was set. + */ + public function testInstaller() { + $this->assertEqual(\Drupal::config('system.site')->get('mail'), $this->profile_site_mail); + $this->assertEqual(\Drupal::config('system.date')->get('timezone.default'), $this->profile_timezone); + } + +} 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); +}