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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

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

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

Remove page type from Create dropdown in CMS


Go to End


8 Posts   5767 Views

Avatar
noizy

Community Member, 25 Posts

2 April 2008 at 4:48pm

I've got a page type that I don't want users to be able to add any more instances of to the site.

How can I restrict it, or (ideally) remove it from the Create dropdown in the CMS?

Avatar
(deleted)

Community Member, 473 Posts

2 April 2008 at 4:50pm

/**
* If this is false, the class cannot be created in the CMS.
* @var boolean
*/
static $can_create = true;

Set it to false (:

Avatar
noizy

Community Member, 25 Posts

2 April 2008 at 5:01pm

Edited: 02/04/2008 5:08pm

thanks Simon.

Tried it, doesn't work for me. I can still quite happily add pages to the site.

Interestingly, it *does* make it impossible to delete those pages via the CMS (the check option is greyed out when I choose 'Delete the selected page').

I also added...

static $can_be_root = false;

to my class, and that doesn't seem to have any effect either.

Avatar
(deleted)

Community Member, 473 Posts

2 April 2008 at 5:05pm

hmm, try defining canCreate() and return false.

Avatar
noizy

Community Member, 25 Posts

2 April 2008 at 5:09pm

Edited: 02/04/2008 5:12pm

ok, this worked...

static $can_create = MyPageType::canCreate;
function canCreate(){
    return false;
}

Avatar
noizy

Community Member, 25 Posts

2 April 2008 at 5:12pm

But ... why?

Avatar
(deleted)

Community Member, 473 Posts

2 April 2008 at 5:14pm

Because you're an admin.

By default, setting $can_create to false only stops those that aren't full admins from creating the page.

As you overwrote canCreate() to always return false, no one can create it.

Avatar
noizy

Community Member, 25 Posts

2 April 2008 at 5:15pm

aha. I see. cheers.