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.

Archive

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

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

Hiding a class from 'Create' menu.


Reply

3 Posts   2002 Views

Avatar
xmedeko

20 July 2007 at 10:47am (Last edited: 20 July 2007 2:47pm), Community Member, 94 Posts

Hi,
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:

CMSMain::PageTypes()
SiteTree:getClassDropdown()

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 @@
      array_shift($classes);
      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 :-(

Avatar
Andy

25 July 2007 at 9:50am 230 Posts

Thanks for this! :)

Avatar
mallbeury

17 September 2008 at 7:06pm Community Member, 7 Posts

Hi,

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.

Matt