Skip to content
Browse files

MINOR Merged from trunk

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@79282 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information...
1 parent 69406d0 commit 3edc596bdba18b9fed42ee39a9af3ce31b80e968 @chillu chillu committed with sminnee
View
15 core/model/Translatable.php
@@ -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() {
@@ -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) );
@@ -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));
View
3 javascript/TreeSelectorField.js
@@ -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
34 tests/model/TranslatableTest.php
@@ -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 {
View
10 tests/model/TranslatableTest.yml
@@ -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.
Something went wrong with that request. Please try again.