Unverified Commit 04d46f62 authored by alexpott's avatar alexpott

Issue #2849074 by decafdennis, alexpott, zuuperman, AdamPS, sagesolutions,...

Issue #2849074 by decafdennis, alexpott, zuuperman, AdamPS, sagesolutions, tucho, xjm: SiteConfigureForm overrides value from install profile
parent 36c5538b
......@@ -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,
......@@ -207,11 +210,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),
'#weight' => 5,
'#attributes' => ['class' => ['timezone-detect']],
......
name: Testing site config
type: profile
description: 'Minimal profile for testing with default site config.'
version: VERSION
core: 8.x
hidden: true
<?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);
}
<?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);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment