Jump to:

1851 Posts in 1606 Topics by 561 members

Blog Module

SilverStripe Forums » Blog Module » Setting PageType to BlogEntry

Discuss the Blog Module.

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

Page: 1
Go to End
Author Topic: 968 Views
  • Hoppi
    Avatar
    Community Member
    1 Post

    Setting PageType to BlogEntry Link to this post

    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/

    968 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.