MINOR Merged from trunk

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@79282 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2009-06-16 00:11:19 +00:00 committed by Sam Minnee
parent 69406d0fb0
commit 3edc596bdb
4 changed files with 60 additions and 2 deletions

View File

@ -428,7 +428,11 @@ class Translatable extends DataObjectDecorator {
parent::setOwner($owner);
// setting translatable fields by inspecting owner - this should really be done in the constructor
$this->translatableFields = array_keys($this->owner->inheritedDatabaseFields());
$this->translatableFields = array_merge(
array_keys($this->owner->inheritedDatabaseFields()),
array_keys($this->owner->has_many()),
array_keys($this->owner->many_many())
);
}
function extraStatics() {
@ -789,6 +793,13 @@ class Translatable extends DataObjectDecorator {
// Don't apply these modifications for normal DataObjects - they rely on CMSMain logic
if(!($this->owner instanceof SiteTree)) return;
$excludeFields = array(
'ViewerGroups',
'EditorGroups',
'CanViewType',
'CanEditType'
);
// used in CMSMain->init() to set language state when reading/writing record
$fields->push(new HiddenField("Locale", "Locale", $this->owner->Locale) );
@ -831,6 +842,8 @@ class Translatable extends DataObjectDecorator {
// (fields are object references, so we can replace them with the translatable CompositeField)
foreach($allDataFields as $dataField) {
if($dataField instanceof HiddenField) continue;
if(in_array($dataField->Name(), $excludeFields)) continue;
if(in_array($dataField->Name(), $translatableFieldNames)) {
// if the field is translatable, perform transformation
$fields->replaceField($dataField->Name(), $transformation->transformFormField($dataField));

View File

@ -144,6 +144,8 @@ TreeDropdownField.prototype = {
ajaxGetTree: function(after) {
var ajaxURL = this.helperURLBase() + 'gettree?forceValues=' + this.inputTag.value;
ajaxURL += $('SecurityID') ? '&SecurityID=' + $('SecurityID').value : '';
if($('Form_EditForm_Locale')) ajaxURL += "&locale=" + $('Form_EditForm_Locale').value;
new Ajax.Request(ajaxURL, {
method : 'get',
onSuccess : after,
@ -190,6 +192,7 @@ TreeDropdownField.prototype = {
var ajaxURL = this.options.dropdownField.helperURLBase() + 'getsubtree?&SubtreeRootID=' + this.getIdx();
ajaxURL += $('SecurityID') ? '&SecurityID=' + $('SecurityID').value : '';
if($('Form_EditForm_Locale')) ajaxURL += "&locale=" + $('Form_EditForm_Locale').value;
new Ajax.Request(ajaxURL, {
onSuccess : this.installSubtree.bind(this),

View File

@ -770,6 +770,40 @@ class TranslatableTest extends FunctionalTest {
Translatable::set_allowed_locales($origAllowedLocales);
}
function testSavePageInCMS() {
$adminUser = $this->objFromFixture('Member', 'admin');
$enPage = $this->objFromFixture('Page', 'testpage_en');
$group = new Group();
$group->Title = 'Example Group';
$group->write();
$frPage = $enPage->createTranslation('fr_FR');
$frPage->write();
$adminUser->logIn();
$cmsMain = new CMSMain();
$origLocale = Translatable::get_current_locale();
Translatable::set_current_locale('fr_FR');
$form = $cmsMain->getEditForm($frPage->ID);
$form->loadDataFrom(array(
'Title' => 'Translated', // $db field
'ViewerGroups' => $group->ID // $many_many field
));
$form->saveInto($frPage);
$frPage->write();
$this->assertEquals('Translated', $frPage->Title);
$this->assertEquals(array($group->ID), $frPage->ViewerGroups()->column('ID'));
$adminUser->logOut();
Translatable::set_current_locale($origLocale);
}
}
class TranslatableTest_DataObject extends DataObject implements TestOnly {

View File

@ -48,13 +48,21 @@ TranslatableTest_Page:
Group:
cmseditorgroup:
Code: cmseditorgroup
admingroup:
Code: admingroup
Member:
cmseditor:
FirstName: Editor
Groups: =>Group.cmseditorgroup
websiteuser:
FirstName: Website User
admin:
FirstName: Admin
Groups: =>Group.admingroup
Permission:
cmsmaincode:
Code: CMS_ACCESS_CMSMain
Group: =>Group.cmseditorgroup
Group: =>Group.cmseditorgroup
admincode:
Code: ADMIN
Group: =>Group.admingroup