Jump to:

23483 Posts in 18976 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » How to hide a page type from CMS

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 2
Go to End
Author Topic: 4752 Views
  • micahsheets
    Avatar
    Community Member
    164 Posts

    How to hide a page type from CMS Link to this post

    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.

  • banal
    Avatar
    Community Member
    901 Posts

    Re: How to hide a page type from CMS Link to this post

    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.

  • schellmax
    Avatar
    Community Member
    126 Posts

    Re: How to hide a page type from CMS Link to this post

    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

  • micahsheets
    Avatar
    Community Member
    164 Posts

    Re: How to hide a page type from CMS Link to this post

    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.

  • bartvanirsel
    Avatar
    Community Member
    94 Posts

    Re: How to hide a page type from CMS Link to this post

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

  • amdayton
    Avatar
    Community Member
    8 Posts

    Re: How to hide a page type from CMS Link to this post

    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.

  • martimiz
    Avatar
    Forum Moderator
    1086 Posts

    Re: How to hide a page type from CMS Link to this post

    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)

  • bartvanirsel
    Avatar
    Community Member
    94 Posts

    Re: How to hide a page type from CMS Link to this post

    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.

    4752 Views
Page: 1 2
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.