Jump to:

23355 Posts in 17744 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » [Solved] How do I hide page type from a module?

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

Page: 1
Go to End
Author Topic: 1233 Views
  • redactuk
    Avatar
    Community Member
    115 Posts

    [Solved] How do I hide page type from a module? Link to this post

    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?

  • mark_s
    Avatar
    Community Member
    78 Posts

    Re: [Solved] How do I hide page type from a module? Link to this post

    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

  • redactuk
    Avatar
    Community Member
    115 Posts

    Re: [Solved] How do I hide page type from a module? Link to this post

    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;

  • redactuk
    Avatar
    Community Member
    115 Posts

    Re: [Solved] How do I hide page type from a module? Link to this post

    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';

  • TotalNet
    Avatar
    Community Member
    181 Posts

    Re: [Solved] How do I hide page type from a module? Link to this post

    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.

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