Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba

Translatable and Data Object Manager

Go to End

6 Posts   4362 Views


Community Member, 34 Posts

15 June 2009 at 2:31pm

Hi UncleCheeze!

Sites that enable translation won't work with Data Object Manager.

The main problem is that the locale parameter is not propagated in most requests.

Anyway, I found a work around, and I think you might be interrested to include those changes in your trunk!

First, I need to enable translations for all the classes (SiteTree, all classes using DataObject), and also for the DataObjectManager and DataObjectManager_Item classes. For those two last, I know it's bad, but it's the work around I found.

so, in my _config.php, I have :

Object::add_extension('SiteTree', 'Translatable');
Object::add_extension('Performer', 'Translatable');
Object::add_extension('DataObjectManager', 'Translatable');
Object::add_extension('DataObjectManager_Item', 'Translatable');

After /dev/build, you'll see there's a Locale DB field add for DataObject classes (Performer, in my case)

Then, in the Performer Class, i need to add an hidden field :

	function getCMSFields_forPopup() {
		$fields = new FieldSet();
		$fields->push( new TextField( 'FullName', 'Nom' ) );
		$fields->push( new TextField( 'Tagline' ) );
		$fields->push( new TextField( 'Web' ) );
		$fields->push( new HiddenField( $name='Locale', $title='Locale', $value=Translatable::get_current_locale() ) );
		return $fields;

It would be good if the the field would add up itself... But I didn't have the time to work on it...

After, I needed to edit you DataObjectManager.php :

Modify getQueryString method :

	protected function getQueryString($params = array())
		$per_page = isset($params['per_page'])? $params['per_page'] : 	$this->per_page;
		$show_all = isset($params['show_all'])? $params['show_all'] : 	$this->showAll;
		$sort 	  = isset($params['sort'])? $params['sort'] 		: 	$this->sort;
		$sort_dir = isset($params['sort_dir'])? $params['sort_dir'] : 	$this->sort_dir;
		$filter   = isset($params['filter'])? $params['filter'] 	: 	$this->filter;
		$search   = isset($params['search'])? $params['search'] 	: 	$this->search;
		$locale = $this->hasExtension('Translatable') ? "&locale=".Translatable::get_current_locale() : '';

		return "ctf[{$this->Name()}][per_page]={$per_page}&ctf[{$this->Name()}][showall]={$show_all}&ctf[{$this->Name()}][sort]={$sort}&ctf[{$this->Name()}][sort_dir]={$sort_dir}&ctf[{$this->Name()}][search]={$search}&ctf[{$this->Name()}][filter]={$filter}".$locale;

Modify the AddLink method :

	public function AddLink() {
		$currentLang = ($this->hasExtension('Translatable')) ? '?locale='.Translatable::get_current_locale() : '';
		return $this->BaseLink() . '/add'.$currentLang;

And add thoses methods for the DataObjectManager_Item class :

	public function EditLink() {
		$currentLang = ($this->hasExtension('Translatable')) ? '?locale='.Translatable::get_current_locale() : '';
		return parent::EditLink().$currentLang;
	public function DeleteLink() {
		$currentLang = ($this->hasExtension('Translatable')) ? '?locale='.Translatable::get_current_locale() : '';
		return parent::DeleteLink().$currentLang;

So it works for a has_many relationship. I think I gonna have to work a little more for a many_many relationship. Thank god, I don't have to use a FileObjectManager !!!

For now I broke the code, so I can't get (easily) in sync with your trunk!

I know this issue involves a lot of work... And thanks for your good work!



Forum Moderator, 4102 Posts

16 June 2009 at 5:21am

Looks interesting. Thanks for looking into this. Is there a better way to do this? I'm not sure what the Translatable extension is, but how are other modules adapting to it? Does this information have to be passed through the request?


Community Member, 34 Posts

16 June 2009 at 5:44am

I'm not sure how to handle it correctly... but for sure the 'locale' parameter must be passed for requests that deal with translated objects.

Maybe you'll have to get a look deeper about multilangual content :

You can try to setup a small site using a has_many relationship (testimonials, for example). Enable translations like the doc says, and starts translating a page that has a DataObjectManager attached to it.

Maybe SS team would help!
Good luck!



Community Member, 6 Posts

15 July 2009 at 8:19pm

Edited: 15/07/2009 11:20pm

I am having the same problem with my site Johnny, but I do not understand the exact location of the files that you edited.
I also have translatable enabled. I have a french translation side to my site. The image gallery works great until I switch to my french language translation side to my site, every time I try to upload a photo... I get nothing in the popup window - acutually where I should have the option to upload a photo in the popup window it gives me the error page on my site.


Community Member, 11 Posts

20 April 2010 at 11:44pm


is there a defined way to use the DataObjectManager with Translatable?
Johnny's recipe doesn't work for Silverstripe 2.3.3

I always get an error
DataObjectDecorator->setOwner(): Trying to decorate an object of class 'DataObjectManager' with 'Translatable', only Dataobject subclasses are supported.


Community Member, 288 Posts

22 April 2010 at 7:27pm

The easiest way of fixing this is to edit CMSMain.php and store the locale in the session.
The ticket is here along with a patch for the fix.

In all my testing I have never gotten this to work properly in the 2.3.x branch but the fix works properly if you run on the 2.4 branch from the SVN like I'm doing right now. The responsible method for this should be the Link method in CMSMain.php but modifying that has pretty far reaching consequences so it's not recommended trying that.

If anyone wants to go the DOM route like Johnny does then I would recommend extending the classes you need and overwriting the methods so you don't touch the original code. However I would really recommend using the CMSMain patch since it's so much simpler and it shouldn't be up to the DOM to keep track of locale variables.

Simply download the patch and apply it to CMSMain.php. If you want to update via SVN simply revert the file, update from SVN and then apply the patch again. I personally have a couple of modified files in the core and having all my fixes in a patch makes updating so much easier.