jamckp jamckp - 2 months ago 12
Javascript Question

Remove 'Duplicate this page and subpages' functionality in Silverstripe

In Silverstripe if you right click on a page in Sitetree you have the ability to duplicate either a single page or a page and all its children.

enter image description here

We have found that users occasionally duplicate pages with large numbers of children and would like to prevent this by either removing the 'This page and subpages' option or by restricting it to admin users only.

How can this be achieved?

Answer

Adding the following code to page.php prevents non admin users from duplicating pages and subpages. The menu item is still visible which is suboptimal but is good enough as a quick solution.

public function duplicateWithChildren() {
    if(!Permission::check('ADMIN')) {
        throw new ValidationException("You must be logged in as an Admin to duplicate a page and subpages");
    }
    return parent::duplicateWithChildren();
}
Comments