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.

General Questions /

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

[Solved] How do I hide page type from a module?


Reply


5 Posts   1329 Views

Avatar
redactuk

Community Member, 117 Posts

13 July 2010 at 1:23pm

Edited: 14/07/2010 12:22pm

I'm made a slight extension to ImageGalleryPage, so my new page type is MyImageGalleryPage. What i need to do now is ensure that even Admin user on a website is not given option to create a page using the original page type.

Now I've found both these threads:

http://www.silverstripe.org/general-questions/show/258913?start=0
http://silverstripe.org/archive/show/51003?start=0#post51031

but both suggest making change to the page you 3wish to disable, in my case ImageGalleryPage.php

Now my problem is that if I do that then this change will be negated every time I upgrade the ImageGallery module.

Can I disable ImageGalleryPage from within MyImageGalleryPage.php?

Avatar
mark_s

Community Member, 78 Posts

13 July 2010 at 11:18pm

Hi.

When you subclass a Page (or derivative of SiteTree, more specifically), and you don't want people creating instances of the base class, you can define in the subclass:

static $hide_ancestor = true;

So you would put that in MyImageGalleryPage to prevent ImageGalleryPage from showing as a create option.

Is that the behaviour you're after?

Mark

Avatar
redactuk

Community Member, 117 Posts

14 July 2010 at 3:22am

Thanks for reply Mark.

Yes that's what I want to achieve but your suggestion is not working... i.e. ImageGalleryPage still appears in page type drop-down.

Presumably at the start of class definition is fine?

class MyImageGalleryPage extends ImageGalleryPage
{

   static $hide_ancestor = true;

Avatar
redactuk

Community Member, 117 Posts

14 July 2010 at 12:21pm

Ok the correct usage seems to be to specify the name of the parent page type you wish to hide i.e.

static $hide_ancestor = 'ImageGalleryPage';

Avatar
TotalNet

Community Member, 181 Posts

14 July 2010 at 1:02pm

Yeah, it is a little confusing but as an interesting side effect, you can hide any page type from the drop-down, if you didn't want to create a decorator, simply by putting it's class in there - in your Page class for example:

static $hide_ancestor = "ErrorPage";


would remove the error page from the drop down.