5541 Posts in 1738 Topics by 1224 members
|Go to End|
15 October 2010 at 2:42am Last edited: 15 October 2010 2:45am
there was a method Director::get_site_mode() which returned a string ('cms' or 'site'), but it seems to have been deprecated in 2.4: http://open.silverstripe.org/changeset/80055/modules/sapphire/trunk/core/control/Director.php
unfortunately i can't find a replacement for this...
15 October 2010 at 9:30am
*smile* Yep, the Director class was the first place I looked, followed by a rummage in the cmsmain/leftandmain and the rest but couldn't spot anything obvious. Had look at the Director code "deprecated as no longer necessary". I beg to differ (O:
15 October 2010 at 10:18am
You could try grabbing the current controller and check if it extends LeftAndMain. If it does you're in the admin area.
Try something like
15 October 2010 at 12:27pm Last edited: 15 October 2010 12:27pm
Hmm. That is still taking just as much of a chance as my own hack. It would be nice to have an official method. I say this as the augmentStageChildren approach seems to be an approved way of extending (as usual feel free to correct me!) and is active in both web page delivery and CMS aspects where, as demoed here, you might want to have more than one behaviour based on what is going on. That said I must say I am still having fun with SS, even that includes more than a few late nights.
15 October 2010 at 4:34pm Last edited: 16 October 2010 10:46am
Gotta get a proper method to determine CMS vs web delivery as I am finding this augmentStageChildren very handy. While I wait patiently for an approved and maintained method to 'how to tell if in CMS or displaying web page' you can amuse yourself with this wee piece of code based on the same approach:
By default pages in sidebars, menus and the rest get sorted in the order they appear in the CMS, unless you have a specific page control to do otherwise. If you have a lot of pages and desire alphabetical order on any random page or chunk of tree in the site (for example a list of people) it can become a pain to shuffle them all around in the CMS. IMO it can also be easier for people to find something if they know the list is in order.
Enter 'SortChildren'. I've implemented a SiteConfig decorator to provide site wide default settings and a SiteTree decorator that inherits or starts a new set of settings for a page and its children. Settings being whether to sort children alphabetically, leave in CMS order, or reverse sorting. With blocking and inheritance (i.e. the changed page becomes the new default for all pages below). It of course does need to know when it is in the CMS or not because it only want to do it for output. Although having written that I've just thought... wonder what would happen if it had an option to sort the CMS pages so they always end up alphabetical? Crash and Burn?
I'm starting to think this might be used to implement the 'only show what they are allowed to edit BUT also show minimal path of non-editables to' in the CMS based on "is allowed to edit object? no... but does it have a child they can? yes then keep it otherwise don't". That could be a nasty load generator for when able to edit heaps, but could also be set to not process for admins or users with a Permission. For other more constrained users who can only work with a handful of items and assuming the site tree isn't too deep it might speed things up.
And please please don't tell me that augmentStageChildren is going to be deprecated (O"
[[ FILE REMOVED LATER VERSION IMPLEMENTING SMURKAS' CHECK BELOW ]]
15 October 2010 at 8:14pm
Well yes it's as risky as your own check and the check I suggested makes alot of sense. All the CMS areas inherit LeftAndMain so checking for it makes sense. I don't think there's one approved way of checking if you're currently in the CMS so I think you're going to have to settle either for your own solution or some other non deprecated way of finding out if you're currently in the CMS.
I'd just make sure that whatever method you choose to use doesn't run the risk of generating false positives.
16 October 2010 at 10:48am Last edited: 16 October 2010 9:10pm
Fair comment and I've switched to your suggested method. But still waiting to see if any non deprecated method exists.
Oh and out of amusement I added a toggle in sort children to see what would happen if it was allowed to sort the CMS (put in switch at SiteConfig level). Which isn't that silly really as it makes working with piles of user profile pages much easier as you can (as mentioned in a previous post) quickly scan an alpha sorted list to see if the entry is there and don't have to worry about, e.g, dragging/dropping new user pages into the correct name of person order.
|Go to Top|