Jump to:

1132 Posts in 1966 Topics by 403 members

Upgrading SilverStripe

SilverStripe Forums » Upgrading SilverStripe » replacement for get_site_mode ?

Ask questions about upgrading SilverStripe to the latest version.

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

Page: 1
Go to End
Author Topic: 1083 Views
  • Banana
    Avatar
    Community Member
    18 Posts

    replacement for get_site_mode ? Link to this post

    Hello,

    since 2.4 DIrector::get_site_mode() is deprecated and throws a user error
    ( the error message is also misleading, since it is copied from set_site_mode() )

    but I can't find a replacement for this function ?

    how do I know determine if I'm on site or cms ?

    thx,
    Banana

  • simon_w
    Avatar
    Forum Moderator
    467 Posts

    Re: replacement for get_site_mode ? Link to this post

    May I ask why you want to be able to tell the difference between the front and backends? This is usually a sign that controller and model code aren't being kept as separate as they should be.

    Though, in response to your question, one way I've been suggesting to people to check, is check if there is a theme set.

  • Banana
    Avatar
    Community Member
    18 Posts

    Re: replacement for get_site_mode ? Link to this post

    the idea is that I "overwrite" the canView function to check a additional custom field.

    the model has a new field which stores a date. if this date is older a given date, the page should not be accessable.
    But in the cms it should be editable.

    I've this from a module, which creates a start and end date for a model. This model used the Director::get_site_mode() to return true if the model is loaded in the cms.

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: replacement for get_site_mode ? Link to this post

    Might also be able to do your own work around for it

    if(Controller::curr() instanceof LeftAndMain) { }

    /via Sean

  • Banana
    Avatar
    Community Member
    18 Posts

    Re: replacement for get_site_mode ? Link to this post

    git it working with the SSViewer::current:theme().
    it is only set at frontend.

    I needed to extend the canView function, otherwise the available check will be done only at the load/init of the page. But the link to this page would be still there.

    How it works:

    in class Page:
    function canView($member=null){
    $ret = parent::canView();
    $theme = SSViewer::current_theme();
    if(!empty($theme)) {
    # do your custom check
    $ret = customCheck();
    }
    return $ret;
    }

    in controller:
    function init(){
    parent:init();
    $check = $this->_customCheck(); # the same as above
    if(empty($check)) {
    # do something
    }
    }

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