diff --git a/core/model/SiteTree.php b/core/model/SiteTree.php index d7a361446..9c51896ac 100644 --- a/core/model/SiteTree.php +++ b/core/model/SiteTree.php @@ -150,7 +150,16 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid */ static $can_create = true; - + /** + * If this is true, users can create only one instance of this class in the CMS. + */ + static $single_instance_only = false; + + /** + * This is used as a CSS class to indicate a sitetree node is a single_instance_only page type + */ + static $single_instance_only_css_class = 'singleinstanceonly'; + /** * Icon to use in the CMS * @@ -724,6 +733,8 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid * @return boolean True if the current user can create pages on this class. */ public function canCreate($member = null) { + if($this->stat('single_instance_only') && DataObject::get_one($this->class)) return false; + if(!$member || !(is_a($member, 'Member')) || is_numeric($member)) $member = Member::currentUser(); if($member && Permission::checkMember($member, "ADMIN")) return true; @@ -739,7 +750,6 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid return $this->stat('can_create') != false || Director::isDev(); } - /** * This function should return true if the current user can edit this * page. It can be overloaded to customise the security model for an @@ -1814,6 +1824,9 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid if(!$this->ShowInMenus) $classes .= " notinmenu"; + if($this->stat('single_instance_only')) + $classes .= " " . $this->stat('single_instance_only_css_class'); + //TODO: Add integration /* if($this->hasExtension('Translatable') && $controller->Locale != Translatable::default_locale() && !$this->isTranslation())