From 55037b509c1bbeff1c8b8907031aad1ff46f6948 Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Sat, 2 Feb 2019 12:43:03 +0000 Subject: [PATCH] Issue #2849074 by decafdennis, alexpott, zuuperman, AdamPS, sagesolutions, tucho, xjm: SiteConfigureForm overrides value from install profile (cherry picked from commit 04d46f628d5c3d58958f286a1bd1844159e69cb3) --- .../Core/Installer/Form/SiteConfigureForm.php | 12 +++- .../testing_site_config.info.yml | 6 ++ .../testing_site_config.install | 22 +++++++ .../InstallerSiteConfigProfileTest.php | 63 +++++++++++++++++++ 4 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 core/profiles/testing_site_config/testing_site_config.info.yml create mode 100644 core/profiles/testing_site_config/testing_site_config.install create mode 100644 core/tests/Drupal/FunctionalTests/Installer/InstallerSiteConfigProfileTest.php diff --git a/core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php b/core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php index 2cca96259993..9525de6b1891 100644 --- a/core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php +++ b/core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php @@ -158,10 +158,13 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#weight' => -20, '#access' => empty($install_state['config_install_path']), ]; + // 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, @@ -208,11 +211,14 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#weight' => 0, '#access' => empty($install_state['config_install_path']), ]; + // 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(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/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 000000000000..31a390557e08 --- /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 000000000000..0f718d0b8f49 --- /dev/null +++ b/core/profiles/testing_site_config/testing_site_config.install @@ -0,0 +1,22 @@ +<?php + +/** + * @file + * Install functions for the testing_site_config module. + */ + +/** + * Implements hook_install(). + */ +function testing_site_config_install() { + // Set the site email address to something that is not sendmail_from. + \Drupal::configFactory()->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 (which is + // Australia/Sydney in the testing environment). + \Drupal::configFactory()->getEditable('system.date') + ->set('timezone.default', 'America/Los_Angeles') + ->save(TRUE); +} diff --git a/core/tests/Drupal/FunctionalTests/Installer/InstallerSiteConfigProfileTest.php b/core/tests/Drupal/FunctionalTests/Installer/InstallerSiteConfigProfileTest.php new file mode 100644 index 000000000000..791befd0468b --- /dev/null +++ b/core/tests/Drupal/FunctionalTests/Installer/InstallerSiteConfigProfileTest.php @@ -0,0 +1,63 @@ +<?php + +namespace Drupal\FunctionalTests\Installer; + +/** + * Verifies that the installer defaults to the existing site email address and + * timezone, if they were provided by the install profile. + * + * @group Installer + */ +class InstallerSiteConfigProfileTest extends InstallerTestBase { + + /** + * {@inheritdoc} + */ + protected $profile = 'testing_site_config'; + + /** + * The site mail we expect to be set from the install profile. + * + * @see testing_site_config_install() + */ + const EXPECTED_SITE_MAIL = 'profile-testing-site-config@example.com'; + + /** + * The timezone we expect to be set from the install profile. + * + * @see testing_site_config_install() + */ + const EXPECTED_TIMEZONE = 'America/Los_Angeles'; + + /** + * {@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', self::EXPECTED_SITE_MAIL); + $this->assertFieldByName('date_default_timezone', self::EXPECTED_TIMEZONE); + + return parent::setUpSite(); + } + + /** + * Verify the correct site config was set. + */ + public function testInstaller() { + $this->assertEqual($this->config('system.site')->get('mail'), self::EXPECTED_SITE_MAIL); + $this->assertEqual($this->config('system.date')->get('timezone.default'), self::EXPECTED_TIMEZONE); + } + +} -- GitLab