mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-30 05:09:06 +02:00
Merge pull request #8423 from creative-commoners/pulls/4.2/default-locale-for-members
FIX New members now receive the configured default locale, not the current locale
This commit is contained in:
commit
7f685b0bea
@ -268,7 +268,7 @@ class Member extends DataObject
|
|||||||
public function populateDefaults()
|
public function populateDefaults()
|
||||||
{
|
{
|
||||||
parent::populateDefaults();
|
parent::populateDefaults();
|
||||||
$this->Locale = i18n::get_locale();
|
$this->Locale = i18n::config()->get('default_locale');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function requireDefaultRecords()
|
public function requireDefaultRecords()
|
||||||
@ -929,7 +929,7 @@ class Member extends DataObject
|
|||||||
|
|
||||||
// save locale
|
// save locale
|
||||||
if (!$this->Locale) {
|
if (!$this->Locale) {
|
||||||
$this->Locale = i18n::get_locale();
|
$this->Locale = i18n::config()->get('default_locale');
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::onBeforeWrite();
|
parent::onBeforeWrite();
|
||||||
@ -1228,7 +1228,7 @@ class Member extends DataObject
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the date format based on the user's chosen locale,
|
* Return the date format based on the user's chosen locale,
|
||||||
* falling back to the default format defined by the {@link i18n.get_locale()} setting.
|
* falling back to the default format defined by the i18n::config()->get('default_locale') config setting.
|
||||||
*
|
*
|
||||||
* @return string ISO date format
|
* @return string ISO date format
|
||||||
*/
|
*/
|
||||||
@ -1247,7 +1247,7 @@ class Member extends DataObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get user locale
|
* Get user locale, falling back to the configured default locale
|
||||||
*/
|
*/
|
||||||
public function getLocale()
|
public function getLocale()
|
||||||
{
|
{
|
||||||
@ -1256,12 +1256,12 @@ class Member extends DataObject
|
|||||||
return $locale;
|
return $locale;
|
||||||
}
|
}
|
||||||
|
|
||||||
return i18n::get_locale();
|
return i18n::config()->get('default_locale');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the time format based on the user's chosen locale,
|
* Return the time format based on the user's chosen locale,
|
||||||
* falling back to the default format defined by the {@link i18n.get_locale()} setting.
|
* falling back to the default format defined by the i18n::config()->get('default_locale') config setting.
|
||||||
*
|
*
|
||||||
* @return string ISO date format
|
* @return string ISO date format
|
||||||
*/
|
*/
|
||||||
|
@ -56,6 +56,8 @@ class MemberTest extends FunctionalTest
|
|||||||
|
|
||||||
Member::config()->set('unique_identifier_field', 'Email');
|
Member::config()->set('unique_identifier_field', 'Email');
|
||||||
Member::set_password_validator(null);
|
Member::set_password_validator(null);
|
||||||
|
|
||||||
|
i18n::set_locale('en_US');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPasswordEncryptionUpdatedOnChangedPassword()
|
public function testPasswordEncryptionUpdatedOnChangedPassword()
|
||||||
@ -1533,4 +1535,20 @@ class MemberTest extends FunctionalTest
|
|||||||
$this->assertInstanceOf(ValidationResult::class, $result);
|
$this->assertInstanceOf(ValidationResult::class, $result);
|
||||||
$this->assertFalse($result->isValid());
|
$this->assertFalse($result->isValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testNewMembersReceiveTheDefaultLocale()
|
||||||
|
{
|
||||||
|
// Set a different current locale to the default
|
||||||
|
i18n::set_locale('de_DE');
|
||||||
|
|
||||||
|
$newMember = Member::create();
|
||||||
|
$newMember->update([
|
||||||
|
'FirstName' => 'Leslie',
|
||||||
|
'Surname' => 'Longly',
|
||||||
|
'Email' => 'longly.leslie@example.com',
|
||||||
|
]);
|
||||||
|
$newMember->write();
|
||||||
|
|
||||||
|
$this->assertSame('en_US', $newMember->Locale, 'New members receive the default locale');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user