Issue #2849074 by decafdennis, alexpott, zuuperman, AdamPS, sagesolutions, tucho, xjm: SiteConfigureForm overrides value from install profile
parent
36c5538bb1
commit
04d46f628d
|
@ -158,10 +158,13 @@ class SiteConfigureForm extends ConfigFormBase {
|
||||||
'#weight' => -20,
|
'#weight' => -20,
|
||||||
'#access' => empty($install_state['config_install_path']),
|
'#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'] = [
|
$form['site_information']['site_mail'] = [
|
||||||
'#type' => 'email',
|
'#type' => 'email',
|
||||||
'#title' => $this->t('Site email address'),
|
'#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."),
|
'#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,
|
'#required' => TRUE,
|
||||||
'#weight' => -15,
|
'#weight' => -15,
|
||||||
|
@ -207,11 +210,14 @@ class SiteConfigureForm extends ConfigFormBase {
|
||||||
'#weight' => 0,
|
'#weight' => 0,
|
||||||
'#access' => empty($install_state['config_install_path']),
|
'#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'] = [
|
$form['regional_settings']['date_default_timezone'] = [
|
||||||
'#type' => 'select',
|
'#type' => 'select',
|
||||||
'#title' => $this->t('Default time zone'),
|
'#title' => $this->t('Default time zone'),
|
||||||
// Use system timezone if set, but avoid throwing a warning in PHP >=5.4
|
'#default_value' => $default_timezone,
|
||||||
'#default_value' => @date_default_timezone_get(),
|
|
||||||
'#options' => system_time_zones(NULL, TRUE),
|
'#options' => system_time_zones(NULL, TRUE),
|
||||||
'#weight' => 5,
|
'#weight' => 5,
|
||||||
'#attributes' => ['class' => ['timezone-detect']],
|
'#attributes' => ['class' => ['timezone-detect']],
|
||||||
|
|
|
@ -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
|
|
@ -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);
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue