Jump to:

23358 Posts in 18005 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » Get By Link and Unpublish page

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 1060 Views
  • Cristian
    Avatar
    Community Member
    8 Posts

    Get By Link and Unpublish page Link to this post

    Hi Everyone,

    I'm working with the 2.4 svn build, and use the get_by_link function, it works really well.

    But in this particular case it wont work:

    I try to get a page that is currently in saved mode but not publish. and the get_by_link can't see it, I put the cache to false but same result.

    I also try the switching the stage mode and no succes here is my method:

       public function LocalizePage($url) {                                                                                                
          $page = SiteTree::get_by_link($url, false);                     
                         
          if($page && ($page->Locale != Translatable::get_current_locale())) {
             $page = $page->getTranslation(Translatable::get_current_locale());

             return $page->Link();
          } else {

             $oldMode = Versioned::get_reading_mode();
             Versioned::reading_stage('Stage');
             $page = SiteTree::get_by_link($url, false);      
             Versioned::set_reading_mode($oldMode);

             if($page && ($page->Locale != Translatable::get_current_locale())) {
                $page = $page->getTranslation(Translatable::get_current_locale());

                return $page->Link();            
             }      
          }
          
          return $url;
       }

       

    thanks
    Cristian

    1060 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.