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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

How to hide a page type from CMS


Go to End


12 Posts   11000 Views

Avatar
micahsheets

Community Member, 165 Posts

21 April 2009 at 5:45am

I had asked this question long ago but never received any response and that thread is in the archives now so I am going to ask again and see if anything has changed in the new version of SS.

I am now using SS 2.3.1. I have created a new page type that extends Page and set the static $can_create = false;

I can still see this page type in the create new page dropdown and also in the dropdown that allows changing a pre-existing page to a new type.

I would like to be able to create the page and then never allow it to be created or selected anywhere again.

Avatar
bummzack

Community Member, 904 Posts

21 April 2009 at 8:01pm

Hi micahsheets

From my experience, the $can_create variable doesn't do what it should. What worked for me was to override the canCreate method. Place something like this in your custom Page-Class:

public function canCreate(){
	return false; 
}

It is also more versatile since you could make that return value dependent on the amount of pages created etc.
I don't know why there's such a thing as a canCreate method and a $can_create variable. Must be some sort of backwards-compatibility thing.

Avatar
schellmax

Community Member, 126 Posts

22 April 2009 at 1:32am

found an explanation to this in another thread: http://silverstripe.org/archive/show/51003?start=0#post51031
so, as simon_w mentions, $can_create is not applicable to admins

Avatar
micahsheets

Community Member, 165 Posts

22 April 2009 at 3:59am

It would seem that the method proposed here by banal is the right one. I knew that the $can_create did not apply to admins so I created a limited user and logged in as that user but I could still see the page in the dropdowns.

Avatar
bartvanirsel

Community Member, 96 Posts

30 March 2010 at 2:48am

Edited: 30/03/2010 2:49am

Is it also posible to disable choice for RedriectPage and VirtualPage in the selectbox above the SiteTree?

Avatar
amdayton

Community Member, 8 Posts

19 August 2010 at 2:40am

Yeah, I'd like to bump this one — the issue I'm having is that I want to hide a Page type that's part of a module, which I'd rather not edit if I can avoid it. I created a subclass of the module Page, which is what I'm using in the CMS, but I only want users to be able to create the subclass type and not the original. I tried using DataObjectDecorator:

// disable using regular calendar class in CMS
class Calendar_RemoveFromCMS extends DataObjectDecorator {
	public function canCreate(){ return false; }
}

DataObject::add_extension('Calendar', 'Calendar_RemoveFromCMS');

But it didn't work.

Avatar
martimiz

Forum Moderator, 1391 Posts

11 March 2011 at 6:17am

:-) Just found the weirdest way of removing, in my case, the VirtualPage from the AddPageOptions dropdown without having to hack core or use canCreate(). Just created an extremely superfluous pagetype, like this:

class NoVirtualPage extends VirtualPage implements HiddenClass {
	static $hide_ancestor = 'VirtualPage';
} 

OK, this must definitely be the flu... But I thought I'd share (no, not the flu)

Avatar
bartvanirsel

Community Member, 96 Posts

19 March 2011 at 8:47am

Cool, i'll try this ty for sharing! so you created NoVirtualPage.php for this? Is this 'the' way to do this?
I also tried to disable items with jquery which was no succes.

Go to Top