Jump to:

17452 Posts in 4473 Topics by 1971 members


SilverStripe Forums » Archive » Hiding a class from 'Create' menu.

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Page: 1
Go to End
Author Topic: 1986 Views
  • xmedeko
    Community Member
    94 Posts

    Hiding a class from 'Create' menu. Link to this post

    I have a parent class 'Product' and a child classes like 'Hotel', 'Activity', etc. I do not want users to create a page of type 'Product'. I have looked into to SS code, so the relevant methods are:


    I see I can hide the class Product if it implements the 'HiddenClass' interface. But then all subclasses would be hidden as well.

    There's a weird piece of code in CMSMain::PageTypes(). If the child class has a static variable $hide_ancestor which is equal to the order (number) of a class in the array, which is returned by ClassInfo::getValidSubClasses(), then this class is hidden. And this piece of the code is not implemented in the SiteTree:getClassDropdown().

    CMSMain::PageTypes() also check, if the method canCreate(). Which is suitable solution for me, but this is not implemented in SiteTree:getClassDropdown(), unfortunatelly. This is also a mild security issue. If the permission canCreate fails for the current user, he/she can still create a page of another type and then change the type of the page.

    So, I've made the followin change:

    --- SiteTree.php.orig   2007-07-05 17:20:39.000000000 +1200
    +++ SiteTree.php   2007-07-20 11:28:42.000000000 +1200
    @@ -694,7 +694,8 @@
          foreach($classes as $class) {
             $instance = singleton($class);
    -         if(($instance instanceof HiddenClass) && ($class != $this->class)) continue;
    +         if ((($instance instanceof HiddenClass) || !$instance->canCreate()) &&
    +          ($class != $this->class)) continue;

             $addAction = $instance->uninherited('add_action', true);
             if(!$addAction) $addAction = "a $class";

    However, this does not prevent the user to duplicate the forbidden page

  • Andy
    230 Posts

    Re: Hiding a class from 'Create' menu. Link to this post

    Thanks for this!

  • mallbeury
    Community Member
    7 Posts

    Re: Hiding a class from 'Create' menu. Link to this post


    I'm having difficulty with the 'create' menu. I have say 10 templates, including 'NewsHolderPage' and 'NewsPage'. Now if I have my 'NewsHolderPage' page selected in the sitemap of the cms and want to create a new page then I only want 'NewsPage' to be available. Is this possible?

    Currently the user gets presented with every template whenever they create a page which is not ideal.


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.