7911 Posts in 1354 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » Translatable Data Objects
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 681 Views |
-
Translatable Data Objects

29 November 2010 at 12:37am Last edited: 29 November 2010 12:54am
Hi.
I like to make data objects translatable just the same way, pages are translatable through the site-tree.
When I hit "Translate", the pages are put into the specified language site-tree, but attached objects e.g. images are not copied.
Below you find my approach so far. I'm using SS 2.4.3
Couldn't find a solution in the forums, yet. Perhaps you can help?
_config.php:
Object::add_extension('HeaderImage', 'Translatable');CategoryPage:
class CategoryPage extends Page {static $has_many = array(
'HeaderImages' => 'HeaderImage',
);function getCMSFields() {
$fields = parent::getCMSFields();
$manager = new DataObjectManager(
$this,
'HeaderImages', // relation name
'HeaderImage', // object class
HeaderImage::$field_names, // fields to show in table
HeaderImage::getCMSFields_forPopup(), // form that pops up for edit
"CategoryPageID = {$this->ID}" // a filter to only display item associated with this page
);$manager->setAddTitle('Header');
$manager->setSingleTitle('Header Image');
$manager->setPluralTitle('Header Images');
$manager->setPopupWidth(400);
$manager->setPerPageMap(array(20,40,80));$fields->addFieldToTab('Root.Content.Header', $manager);
}
}HeaderImage.php:
class HeaderImage extends DataObject {static $has_one = array(
'Image' => 'Image',
'Category' => 'Category',
'RootFolder' => 'Folder'
);static $field_names = array(
'Thumbnail' => 'Image',
'Title' => 'Title',
);function getCMSFields_forPopup() {
$fields = new FieldSet();
$picfolderName = $this->RootFolder()->FileName;
$picfolderName = str_replace('assets/','',$picfolderName);
$fields->push(new TextField('Title', 'Title'));
$fields->push(new TextField('Subtitle', 'Subtitle'));
$fields->push(new TextField('Text', 'Text'));
$fields->push(new DropdownField('Alignment','Alignment',singleton('HeaderImage')->dbObject('Alignment')->enumValues()));
$fields->push(new TextField('Link', 'Link'));
$fields->push(new ImageField('Image', 'Image', null, null, null, $picfolderName));return $fields;
}function getThumbnail()
{
if ($Image = $this->Image())
{
return $Image->CMSThumbnail();
}
else
{
return '(No Image)';
}
}public function onBeforeWrite() {
parent::onBeforeWrite();
$this->Locale = Translatable::get_current_locale();
}}
-
Re: Translatable Data Objects

29 November 2010 at 6:52am
My understanding is that Translatable is an extension for SiteTree objects only.
---------------
Silverstripe tips, tutorials, screencasts, and more. http://www.leftandmain.com -
Re: Translatable Data Objects

29 November 2010 at 9:08am
Thank you, UncleCheese.
That exactly was my fear. Do you know any alternatives?
-
Re: Translatable Data Objects

29 November 2010 at 11:25am
How many languages? How many fields are you translating on the object?
-
Re: Translatable Data Objects

29 November 2010 at 8:59pm
At the beginning the will be perhaps 10 languages,
and not more than 10 translations per object. E.g. For an Image GalleryIf possible both should be kept flexible for the admin.
-
Re: Translatable Data Objects

30 November 2010 at 4:18am
I'll be taking this further forward soon...
http://www.silverstripe.org/data-model-questions/show/8397#post293889#post293889
| 681 Views | ||
|
Page:
1
|
Go to Top |


