Semicolon
Semicolon

Reputation: 1914

SilverStripe hide default pagetypes

I'm trying to understand the best practice method of hiding SilverStripe's default pagetypes eg Virtual Page

I'm assuming the code for these pagetypes are buried in the core, which I rather leave untouched. Therefore I've found this method to work:

class HidePageType_VirtualPage extends Page implements HiddenClass { static $hide_ancestor = 'VirtualPage'; }

Although this seems to be the cleanest and least hacky solution, I still wonder if anyone has a better way. Besides, this method is creating a new database column based on the class name, which doesn't make sense considering the goal of hiding a pagetype.

Upvotes: 2

Views: 830

Answers (2)

Brian
Brian

Reputation: 381

Here is the solution from the original post, updated for SilverStripe 4:

<?php

use SilverStripe\CMS\Model\VirtualPage;
use SilverStripe\ORM\HiddenClass;

class HideVirtualPage extends VirtualPage implements HiddenClass {
    private static $hide_ancestor = 'SilverStripe\CMS\Model\VirtualPage';
}

As far as I know this is still the only way to block it from everyone including admins (other than hiding it with CSS). Hopefully a future version of the framework will be adding a $hide_self config var or similar.

Upvotes: 1

bummzack
bummzack

Reputation: 5875

There might be a better Solution, but I'd just create an extension that returns false in the canCreate method. Example:

class CantCreateExtension extends DataExtension
{
    public function canCreate($member)
    {
        return false;
    }
}

Then apply it to the Pages you don't want to be created, by adding the following to your _config.yml:

VirtualPage:
  extensions:
    - CantCreateExtension

Upvotes: 2

Related Questions