Commit 42fcb356 authored by catch's avatar catch

Issue #1934712 by dlu, alexpott, pplantinga, rbayliss, s_leu, Gaelan: Fixed...

Issue #1934712 by dlu, alexpott, pplantinga, rbayliss, s_leu, Gaelan: Fixed Merge system.timezone config object into system.date.
parent b05019fd
......@@ -1896,15 +1896,15 @@ function drupal_handle_request($test_only = FALSE) {
*/
function drupal_get_user_timezone() {
global $user;
$config = config('system.timezone');
$config = config('system.date');
if ($user && $config->get('user.configurable') && $user->isAuthenticated() && $user->getTimezone()) {
if ($user && $config->get('timezone.user.configurable') && $user->isAuthenticated() && $user->getTimezone()) {
return $user->getTimezone();
}
else {
// Ignore PHP strict notice if time zone has not yet been set in the php.ini
// configuration.
$config_data_default_timezone = $config->get('default');
$config_data_default_timezone = $config->get('timezone.default');
return !empty($config_data_default_timezone) ? $config_data_default_timezone : @date_default_timezone_get();
}
}
......
......@@ -2515,11 +2515,8 @@ function install_configure_form_submit($form, &$form_state) {
->set('langcode', language_default()->id)
->save();
config('system.timezone')
->set('default', $form_state['values']['date_default_timezone'])
->save();
config('system.date')
->set('timezone.default', $form_state['values']['date_default_timezone'])
->set('country.default', $form_state['values']['site_default_country'])
->save();
......
......@@ -93,6 +93,26 @@ system.date:
langcode:
type: string
label: 'Default language'
timezone:
type: mapping
label: 'Time zone settings'
mapping:
default:
type: string
label: 'Default time zone'
user:
type: mapping
label: 'User'
mapping:
configurable:
type: boolean
label: 'Users may set their own time zone'
default:
type: integer
label: 'Time zone for new users'
warn:
type: boolean
label: 'Remind users at login if their time zone is not set'
system.date_format.*:
type: mapping
......@@ -288,27 +308,6 @@ system.theme:
- type: string
label: 'Theme'
system.timezone:
type: mapping
label: 'Time zone settings'
mapping:
default:
type: string
label: 'Default time zone'
user:
type: mapping
label: 'User'
mapping:
configurable:
type: boolean
label: 'Users may set their own time zone'
default:
type: integer
label: 'Time zone for new users'
warn:
type: boolean
label: 'Remind users at login if their time zone is not set'
menu.menu.*:
type: mapping
label: 'Menu'
......
first_day: '0'
country:
default: ''
first_day: '0'
timezone:
default: ''
user:
configurable: '1'
warn: '0'
default: '0'
default: ''
user:
configurable: '1'
default: '0'
warn: '0'
......@@ -63,7 +63,6 @@ public function getFormID() {
*/
public function buildForm(array $form, array &$form_state) {
$countries = $this->countryManager->getList();
$system_timezone = $this->configFactory->get('system.timezone');
$system_date = $this->configFactory->get('system.date');
// Date settings:
......@@ -98,11 +97,11 @@ public function buildForm(array $form, array &$form_state) {
$form['timezone']['date_default_timezone'] = array(
'#type' => 'select',
'#title' => t('Default time zone'),
'#default_value' => $system_timezone->get('default') ?: date_default_timezone_get(),
'#default_value' => $system_date->get('timezone.default') ?: date_default_timezone_get(),
'#options' => $zones,
);
$configurable_timezones = $system_timezone->get('user.configurable');
$configurable_timezones = $system_date->get('timezone.user.configurable');;
$form['timezone']['configurable_timezones'] = array(
'#type' => 'checkbox',
'#title' => t('Users may set their own time zone.'),
......@@ -122,14 +121,14 @@ public function buildForm(array $form, array &$form_state) {
$form['timezone']['configurable_timezones_wrapper']['empty_timezone_message'] = array(
'#type' => 'checkbox',
'#title' => t('Remind users at login if their time zone is not set.'),
'#default_value' => $system_timezone->get('user.warn'),
'#default_value' => $system_date->get('timezone.user.warn'),
'#description' => t('Only applied if users may set their own time zone.')
);
$form['timezone']['configurable_timezones_wrapper']['user_default_timezone'] = array(
'#type' => 'radios',
'#title' => t('Time zone for new users'),
'#default_value' => $system_timezone->get('user.default'),
'#default_value' => $system_date->get('timezone.user.default'),
'#options' => array(
DRUPAL_USER_TIMEZONE_DEFAULT => t('Default time zone.'),
DRUPAL_USER_TIMEZONE_EMPTY => t('Empty time zone.'),
......@@ -148,12 +147,10 @@ public function submitForm(array &$form, array &$form_state) {
$this->configFactory->get('system.date')
->set('country.default', $form_state['values']['site_default_country'])
->set('first_day', $form_state['values']['date_first_day'])
->save();
$this->configFactory->get('system.timezone')
->set('default', $form_state['values']['date_default_timezone'])
->set('user.configurable', $form_state['values']['configurable_timezones'])
->set('user.warn', $form_state['values']['empty_timezone_message'])
->set('user.default', $form_state['values']['user_default_timezone'])
->set('timezone.default', $form_state['values']['date_default_timezone'])
->set('timezone.user.configurable', $form_state['values']['configurable_timezones'])
->set('timezone.user.warn', $form_state['values']['empty_timezone_message'])
->set('timezone.user.default', $form_state['values']['user_default_timezone'])
->save();
parent::submitForm($form, $form_state);
......
......@@ -37,8 +37,9 @@ public static function getInfo() {
function setUp() {
parent::setUp('language');
config('system.timezone')
->set('user.configurable', 1)
config('system.date')
->set('timezone.user.configurable', 1)
->save();
$formats = $this->container->get('plugin.manager.entity')
->getStorageController('date_format')
......
......@@ -48,9 +48,9 @@ public function testDateTimezone() {
$date_string = '2007-01-31 21:00:00';
// Make sure no site timezone has been set.
config('system.timezone')
->set('user.configurable', 0)
->set('default', NULL)
config('system.date')
->set('timezone.user.configurable', 0)
->set('timezone.default', NULL)
->save();
// Detect the system timezone.
......@@ -68,7 +68,7 @@ public function testDateTimezone() {
$this->assertTrue($timezone == 'America/Yellowknife', 'DrupalDateTime uses the specified timezone if provided.');
// Set a site timezone.
config('system.timezone')->set('default', 'Europe/Warsaw')->save();
config('system.date')->set('timezone.default', 'Europe/Warsaw')->save();
// Create a date object with an unspecified timezone, which should
// end up using the site timezone.
......@@ -77,7 +77,7 @@ public function testDateTimezone() {
$this->assertTrue($timezone == 'Europe/Warsaw', 'DrupalDateTime uses the site timezone if provided.');
// Create user.
config('system.timezone')->set('user.configurable', 1)->save();
config('system.date')->set('timezone.user.configurable', 1)->save();
$test_user = $this->drupalCreateUser(array());
$this->drupalLogin($test_user);
......
......@@ -43,9 +43,9 @@ function setUp() {
*/
function testTimeZoneHandling() {
// Setup date/time settings for Honolulu time.
$config = config('system.timezone')
->set('default', 'Pacific/Honolulu')
->set('user.configurable', 0)
$config = config('system.date')
->set('timezone.default', 'Pacific/Honolulu')
->set('timezone.user.configurable', 0)
->save();
entity_load('date_format', 'medium')
->setPattern('Y-m-d H:i:s O')
......@@ -64,7 +64,7 @@ function testTimeZoneHandling() {
$this->assertText('2007-07-31 21:00:00 -1000', 'Date should be identical, with GMT offset of -10 hours.');
// Set time zone to Los Angeles time.
$config->set('default', 'America/Los_Angeles')->save();
$config->set('timezone.default', 'America/Los_Angeles')->save();
// Confirm date format and time zone.
$this->drupalGet('node/' . $node1->id());
......
......@@ -1801,12 +1801,9 @@ function system_update_8038() {
'site_default_country' => 'country.default',
'date_first_day' => 'first_day',
'date_default_timezone' => 'timezone.default',
));
update_variables_to_config('system.timezone', array(
'date_default_timezone' => 'default',
'configurable_timezones' => 'user.configurable',
'empty_timezone_message' => 'user.warn',
'user_default_timezone' => 'user.default',
'configurable_timezones' => 'timezone.user.configurable',
'empty_timezone_message' => 'timezone.user.warn',
'user_default_timezone' => 'timezone.user.default',
));
}
......
......@@ -2342,7 +2342,7 @@ function system_custom_theme() {
* Implements hook_form_FORM_ID_alter().
*/
function system_form_user_form_alter(&$form, &$form_state) {
if (config('system.timezone')->get('user.configurable')) {
if (config('system.date')->get('timezone.user.configurable')) {
system_user_timezone($form, $form_state);
}
}
......@@ -2351,8 +2351,8 @@ function system_form_user_form_alter(&$form, &$form_state) {
* Implements hook_form_FORM_ID_alter().
*/
function system_form_user_register_form_alter(&$form, &$form_state) {
$config = config('system.timezone');
if ($config->get('user.configurable') && $config->get('user.default') == DRUPAL_USER_TIMEZONE_SELECT) {
$config = config('system.date');
if ($config->get('timezone.user.configurable') && $config->get('timezone.user.default') == DRUPAL_USER_TIMEZONE_SELECT) {
system_user_timezone($form, $form_state);
}
}
......@@ -2361,9 +2361,9 @@ function system_form_user_register_form_alter(&$form, &$form_state) {
* Implements hook_user_presave().
*/
function system_user_presave(UserInterface $account) {
$config = config('system.timezone');
if ($config->get('user.configurable') && !$account->getTimeZone() && !$config->get('user.default')) {
$account->timezone = $config->get('default');
$config = config('system.date');
if ($config->get('timezone.user.configurable') && !$account->getTimeZone() && !$config->get('timezone.user.default')) {
$account->timezone = $config->get('timezone.default');
}
}
......@@ -2371,9 +2371,9 @@ function system_user_presave(UserInterface $account) {
* Implements hook_user_login().
*/
function system_user_login($account) {
$config = config('system.timezone');
$config = config('system.date');
// If the user has a NULL time zone, notify them to set a time zone.
if (!$account->getTimezone() && $config->get('user.configurable') && $config->get('user.warn')) {
if (!$account->getTimezone() && $config->get('timezone.user.configurable') && $config->get('timezone.user.warn')) {
drupal_set_message(t('Configure your <a href="@user-edit">account time zone setting</a>.', array('@user-edit' => url("user/$account->id()/edit", array('query' => drupal_get_destination(), 'fragment' => 'edit-timezone')))));
}
}
......@@ -2393,7 +2393,7 @@ function system_user_timezone(&$form, &$form_state) {
$form['timezone']['timezone'] = array(
'#type' => 'select',
'#title' => t('Time zone'),
'#default_value' => $account->getTimezone() ? $account->getTimezone() : ($account->id() == $user->id() ? config('system.timezone')->get('default') : ''),
'#default_value' => $account->getTimezone() ? $account->getTimezone() : config('system.date')->get('timezone.default'),
'#options' => system_time_zones($account->id() != $user->id()),
'#description' => t('Select the desired local time and time zone. Dates and times throughout this site will be displayed using this time zone.'),
);
......
......@@ -158,9 +158,9 @@ function testRegistrationDefaultValues() {
->save();
// Set the default timezone to Brussels.
$config_system_timezone = config('system.timezone')
->set('user.configurable', 1)
->set('default', 'Europe/Brussels')
$config_system_date = config('system.date')
->set('timezone.user.configurable', 1)
->set('timezone.default', 'Europe/Brussels')
->save();
// Check that the account information options are not displayed
......@@ -184,7 +184,7 @@ function testRegistrationDefaultValues() {
$this->assertEqual($new_user->getSignature(), '', 'Correct signature field.');
$this->assertTrue(($new_user->getCreatedTime() > REQUEST_TIME - 20 ), 'Correct creation time.');
$this->assertEqual($new_user->isActive(), $config_user_settings->get('register') == USER_REGISTER_VISITORS ? 1 : 0, 'Correct status field.');
$this->assertEqual($new_user->getTimezone(), $config_system_timezone->get('default'), 'Correct time zone field.');
$this->assertEqual($new_user->getTimezone(), $config_system_date->get('timezone.default'), 'Correct time zone field.');
$this->assertEqual($new_user->langcode->value, language_default()->id, 'Correct language field.');
$this->assertEqual($new_user->preferred_langcode->value, language_default()->id, 'Correct preferred language field.');
$this->assertEqual($new_user->init->value, $mail, 'Correct init field.');
......
......@@ -26,9 +26,9 @@ public static function getInfo() {
*/
function testUserTimeZone() {
// Setup date/time settings for Los Angeles time.
config('system.timezone')
->set('user.configurable', 1)
->set('default', 'America/Los_Angeles')
config('system.date')
->set('timezone.user.configurable', 1)
->set('timezone.default', 'America/Los_Angeles')
->save();
entity_load('date_format', 'medium')
->setPattern('Y-m-d H:i T')
......
......@@ -284,9 +284,9 @@ function hook_user_update($account) {
* The user object on which the operation was just performed.
*/
function hook_user_login($account) {
$config = config('system.timezone');
$config = config('system.date');
// If the user has a NULL time zone, notify them to set a time zone.
if (!$account->getTimezone() && $config->get('user.configurable') && $config->get('user.warn')) {
if (!$account->getTimezone() && $config->get('timezone.user.configurable') && $config->get('timezone.user.warn')) {
drupal_set_message(t('Configure your <a href="@user-edit">account time zone setting</a>.', array('@user-edit' => url("user/" . $account->id() . "/edit", array('query' => drupal_get_destination(), 'fragment' => 'edit-timezone')))));
}
}
......
......@@ -218,7 +218,7 @@ function user_field_extra_fields() {
'description' => t('User module form element.'),
'weight' => 0,
);
if (config('system.timezone')->get('user.configurable')) {
if (config('system.date')->get('timezone.user.configurable')) {
$fields['user']['user']['form']['timezone'] = array(
'label' => t('Timezone'),
'description' => t('System module form element.'),
......
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