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
martimiz

Forum Moderator, 1391 Posts

19 March 2011 at 10:19am

Edited: 07/04/2011 3:50am

No, I don't suppose it is 'the' way to do this - it's too weird to have to create a page only to remove it again - just to get rid of the parent as wel. But it did work and I hadn't found another way yet... :-)

Avatar
martimiz

Forum Moderator, 1391 Posts

7 April 2011 at 3:52am

Ok, to be complete - feeling a bit guilty I guess :-( : the preferred way would probably be to use the canCreate() method. Just adding it to your custom MyPage class and having it return false, would remove it from the dropdown:

class MyPage extends Page {

	function canCreate($Member = null) {
		return false; 
	}
	...

Because this would now prevent any user, even the admin, from creating a page of this type, you'd need to build in some conditional. One way to do this, is to create a new permission code within the SecurityAdmin, and check that against the current user.

Check out http://www.ssbits.com/snippets/2009/create-a-permission-code/ for how to create and work with permissions.

I experimented with a (simple) bit of code, where you can define a list of 'restricted' pagetypes using an array from _config.php. If anyone is interested, I'll add a link...

Avatar
svandragt

Community Member, 44 Posts

4 September 2013 at 9:41pm

Edited: 04/09/2013 9:43pm

I created a ProtoPage that extends SiteTree and altered Page to extend from ProtoPage. This allows me to put all base functionality in ProtoPage.

To stop ProtoPage from showing up in the new menu, add the following line to mysite/_config.php (SS 3.0.5):

SiteTree::$hide_ancestor = 'ProtoPage';

Note it's not good practice to set variables directly, but there is no set_hide_ancestor. I assume it's recommended to set the hide_ancestor attribute on individual page types, however you then have to ensure that any page type that inherits sets the value back to the value in SiteTree (null).

Avatar
Harley

Community Member, 165 Posts

5 March 2015 at 3:35pm

Edited: 05/03/2015 3:35pm

Not sure if this will come in handy for anyone but I came across this post researching this issue for myself and thought I would share.

	function canCreate($Member = true) {
		if( DataObject::get('PageTypeClassName')->count() == 0 ){
			return true;
		}
	}

Go to Top