Skip to content

Commit

Permalink
MINOR Merged from trunk
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@79282 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information
chillu authored and Sam Minnee committed Feb 2, 2011
1 parent 69406d0 commit 3edc596
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 deletions.
15 changes: 14 additions & 1 deletion core/model/Translatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,11 @@ function setOwner(Object $owner) {
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() {
Expand Down Expand Up @@ -789,6 +793,13 @@ function updateCMSFields(FieldSet &$fields) {
// 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) );

Expand Down Expand Up @@ -831,6 +842,8 @@ function updateCMSFields(FieldSet &$fields) {
// (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));
Expand Down
3 changes: 3 additions & 0 deletions javascript/TreeSelectorField.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down
34 changes: 34 additions & 0 deletions tests/model/TranslatableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,40 @@ function testCanTranslate() {

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 {
Expand Down
10 changes: 9 additions & 1 deletion tests/model/TranslatableTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 3edc596

Please sign in to comment.