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.

Customising the CMS /

canCreate and Drag-and-Drop


Reply


4 Posts   480 Views

Avatar
_Vince

Community Member, 162 Posts

20 March 2014 at 11:25am

Hi, all.

I have some custom page types, and I only want ONE page of these types to be created.

So I add the following:

/**********************************************************************/
   public function canCreate($member = null) {
/**********************************************************************/
      return !DataObject::get_one($this->ClassName);
   }

and it works well.

BUT... the CMS doesn't let me rearrange the pages. I can't drag and drop them along the site tree.

How can I limit the number of pages?

I've thought of doing something with onBeforeWrite() but that doesn't remove the custom pages from the list of possible page types.

Avatar
_Vince

Community Member, 162 Posts

20 March 2014 at 11:55am

I found this on github

https://github.com/silverstripe/silverstripe-cms/issues/657

which describes the problem perfectly. Unfortunately, I don't understand the "use canEdit()" part. Can someone post an example?

Avatar
Double-A-Ron

Community Member, 604 Posts

21 March 2014 at 5:10pm

I think they posters in that discussion mean that they want to check the canEdit permission in /cms/code/controllers/CMSMain.php SiteTreeHints() (so part of Silverstripe's CMS core).

It seems that the code that handles this is checking canCreate, but not canEdit. So these devs are talking that doing so would resolve the situation.

It also seems that no one has touched this one for quite some time. You could comment on Github to see if there's an update. They were talking about doing it another way, so someone there may know more.

Avatar
_Vince

Community Member, 162 Posts

21 March 2014 at 11:00pm

Cheers, thanks. That's what I thought they meant. :P