block by drzax 3856130

A pattern for creating 'singleton' page types in Silverstripe

See SingletonPage for a maintained version of this gist.

Use this DataExtension to specify that it should only be possible for users to create one instance of the decorated page type.

Note that the use of ‘singleton’ here does not refer to use of the singleton pattern as commonly understood in programming.

Silverstripe core currently prevents DataExtensions from overriding the behaviour of the SiteTree->canCreate() function for users with ADMIN permissions, so an addition to the Page class is also required to properly invoke this DataExtension.

Page.php

SingletonPage.php

_config.php