Skip to content

Commit 48298df

Browse files
committed
Issue #2849074 by decafdennis, alexpott, zuuperman, AdamPS, sagesolutions, tucho, xjm: SiteConfigureForm overrides value from install profile
(cherry picked from commit 04d46f6)
1 parent e187ee1 commit 48298df

File tree

4 files changed

+100
-3
lines changed

4 files changed

+100
-3
lines changed

lib/Drupal/Core/Installer/Form/SiteConfigureForm.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,13 @@ public function buildForm(array $form, FormStateInterface $form_state) {
158158
'#weight' => -20,
159159
'#access' => empty($install_state['config_install_path']),
160160
];
161+
// Use the default site mail if one is already configured, or fall back to
162+
// PHP's configured sendmail_from.
163+
$default_site_mail = $this->config('system.site')->get('mail') ?: ini_get('sendmail_from');
161164
$form['site_information']['site_mail'] = [
162165
'#type' => 'email',
163166
'#title' => $this->t('Site email address'),
164-
'#default_value' => ini_get('sendmail_from'),
167+
'#default_value' => $default_site_mail,
165168
'#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."),
166169
'#required' => TRUE,
167170
'#weight' => -15,
@@ -208,11 +211,14 @@ public function buildForm(array $form, FormStateInterface $form_state) {
208211
'#weight' => 0,
209212
'#access' => empty($install_state['config_install_path']),
210213
];
214+
// Use the default site timezone if one is already configured, or fall back
215+
// to the system timezone if set (and avoid throwing a warning in
216+
// PHP >=5.4).
217+
$default_timezone = $this->config('system.date')->get('timezone.default') ?: @date_default_timezone_get();
211218
$form['regional_settings']['date_default_timezone'] = [
212219
'#type' => 'select',
213220
'#title' => $this->t('Default time zone'),
214-
// Use system timezone if set, but avoid throwing a warning in PHP >=5.4
215-
'#default_value' => @date_default_timezone_get(),
221+
'#default_value' => $default_timezone,
216222
'#options' => system_time_zones(NULL, TRUE),
217223
'#description' => $this->t('By default, dates in this site will be displayed in the chosen time zone.'),
218224
'#weight' => 5,
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name: Testing site config
2+
type: profile
3+
description: 'Minimal profile for testing with default site config.'
4+
version: VERSION
5+
core: 8.x
6+
hidden: true
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/**
4+
* @file
5+
* Install functions for the testing_site_config module.
6+
*/
7+
8+
/**
9+
* Implements hook_install().
10+
*/
11+
function testing_site_config_install() {
12+
// Set the site email address to something that is not sendmail_from.
13+
\Drupal::configFactory()->getEditable('system.site')
14+
->set('mail', '[email protected]')
15+
->save(TRUE);
16+
17+
// Set the time zone to something that is not the system timezone (which is
18+
// Australia/Sydney in the testing environment).
19+
\Drupal::configFactory()->getEditable('system.date')
20+
->set('timezone.default', 'America/Los_Angeles')
21+
->save(TRUE);
22+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace Drupal\FunctionalTests\Installer;
4+
5+
/**
6+
* Verifies that the installer defaults to the existing site email address and
7+
* timezone, if they were provided by the install profile.
8+
*
9+
* @group Installer
10+
*/
11+
class InstallerSiteConfigProfileTest extends InstallerTestBase {
12+
13+
/**
14+
* {@inheritdoc}
15+
*/
16+
protected $profile = 'testing_site_config';
17+
18+
/**
19+
* The site mail we expect to be set from the install profile.
20+
*
21+
* @see testing_site_config_install()
22+
*/
23+
const EXPECTED_SITE_MAIL = '[email protected]';
24+
25+
/**
26+
* The timezone we expect to be set from the install profile.
27+
*
28+
* @see testing_site_config_install()
29+
*/
30+
const EXPECTED_TIMEZONE = 'America/Los_Angeles';
31+
32+
/**
33+
* {@inheritdoc}
34+
*/
35+
protected function installParameters() {
36+
$parameters = parent::installParameters();
37+
38+
// Don't override the site email address, allowing it to default to the one
39+
// from our install profile.
40+
unset($parameters['forms']['install_configure_form']['site_mail']);
41+
42+
return $parameters;
43+
}
44+
45+
/**
46+
* {@inheritdoc}
47+
*/
48+
protected function setUpSite() {
49+
$this->assertFieldByName('site_mail', self::EXPECTED_SITE_MAIL);
50+
$this->assertFieldByName('date_default_timezone', self::EXPECTED_TIMEZONE);
51+
52+
return parent::setUpSite();
53+
}
54+
55+
/**
56+
* Verify the correct site config was set.
57+
*/
58+
public function testInstaller() {
59+
$this->assertEqual($this->config('system.site')->get('mail'), self::EXPECTED_SITE_MAIL);
60+
$this->assertEqual($this->config('system.date')->get('timezone.default'), self::EXPECTED_TIMEZONE);
61+
}
62+
63+
}

0 commit comments

Comments
 (0)