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:

Blog Module /

Discuss the Blog Module.

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

Setting PageType to BlogEntry


Go to End


1323 Views

Avatar
Hoppi

Community Member, 1 Post

14 January 2010 at 12:21am

Hi!
I'm currently trying to force the user to create blogentries in german and english simultaneously, since we use the blog widget for our news.
The problem is that I want to link german and english version of the news, so I'm using createTranslation(). Works well so far if it weren't for two huge problems:

1. The PageType of the translated blogentry object is "none". How can I change this?
2. Despite having the english texts saved, the german ones are displayed in both versions.

Here's the code I'm using:

function postblog($data, $form) {
		if(!Permission::check('BLOGMANAGEMENT')) return Security::permissionFailure();

		Cookie::set("BlogHolder_Name", $data['Author']);
		$blogentry = false;
		
		if(isset($data['ID']) && $data['ID']) {
			$blogentry = DataObject::get_by_id("BlogEntry", $data['ID']);
		}
		
		if(!$blogentry) {
			$blogentry = new BlogEntry();
		}
		
		$form->saveInto($blogentry);
		if(i18n::get_locale() === "de_DE") {
			$blogentry->Content = $form->datafieldByName('BlogPost')->dataValue();
			$blogentry->Title = $form->datafieldByName('Title')->dataValue();
		} else if (i18n::get_locale() === "en_US") {
			$blogentry->Content = $form->datafieldByName('BlogPostEN')->dataValue();
			$blogentry->Title = $form->datafieldByName('TitleEN')->dataValue();
		}
		$blogentry->ParentID = $this->ID;
		$blogentry->Status = "Published";
		$blogentry->writeToStage("Stage");
		$blogentry->publish("Stage", "Live");
		
		$translatedBlogentry = new BlogEntry();
		$form->saveInto($translatedBlogentry);
		//check current language and automatically choose the other one for
		//the translation.
		if(i18n::get_locale() === "de_DE") {
			$translatedBlogentry = $blogentry->createTranslation('en_US');
			unset($translatedBlogentry->Title);
			unset($translatedBlogentry->Content);
			
			$translateBlogentry->PageType = 'BlogEntry';
			$translatedBlogentry->Title = $form->datafieldByName('TitleEN')->dataValue();
			$translatedBlogentry->Content = $form->datafieldByName('BlogPostEN')->dataValue();
			$translatedBlogentry->ParentID = Translatable::get_one_by_locale('BlogHolder', ('en_US'))->ID;
		} else if (i18n::get_locale() === "en_US") {
			$translatedBlogentry = $blogentry->createTranslation('de_DE');
			unset($translatedBlogentry->Title);
			unset($translatedBlogentry->Content);
			
			$translateBlogentry->PageType = 'BlogEntry';
			$translatedBlogentry->Title = $form->datafieldByName('Title')->dataValue();
			$translatedBlogentry->Content = $form->datafieldByName('BlogPost')->dataValue();
			$translatedBlogentry->ParentID = Translatable::get_one_by_locale('BlogHolder', ('de_DE'))->ID;
		}
		
		
		$translatedBlogentry->Status = "Published";
		$translatedBlogentry->writeToStage("Stage");
		$translatedBlogentry->publish("Stage", "Live");
		
		Director::redirect($this->Link());
	}
[/code/