From 68b1cd07dd1f92700bded4fcd612a645df19cecc Mon Sep 17 00:00:00 2001 From: James Cocker Date: Fri, 10 Jul 2020 14:30:23 +0100 Subject: [PATCH] Add ability to disable some extensions via config As not possible to remove extension: https://github.com/silverstripe/silverstripe-framework/issues/8613 https://github.com/silverstripe/silverstripe-cms/issues/2146 https://github.com/silverstripe/silverstripe-config/issues/32 --- code/extensions/CannotCreatePage.php | 4 ++++ code/extensions/PageSettingsHidePermissions.php | 10 ++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/code/extensions/CannotCreatePage.php b/code/extensions/CannotCreatePage.php index ec887c0..d8ca786 100755 --- a/code/extensions/CannotCreatePage.php +++ b/code/extensions/CannotCreatePage.php @@ -11,6 +11,10 @@ class CannotCreatePage extends DataExtension public function canCreate($member = null, $context = array()) { + if ($config = $this->owner->config()->get('can_create')) { + return true; + } + return false; } diff --git a/code/extensions/PageSettingsHidePermissions.php b/code/extensions/PageSettingsHidePermissions.php index 43c028b..2ea9aa8 100644 --- a/code/extensions/PageSettingsHidePermissions.php +++ b/code/extensions/PageSettingsHidePermissions.php @@ -10,9 +10,11 @@ class PageSettingsHidePermissions extends DataExtension public function updateSettingsFields(FieldList $fields) { - $fields->removeFieldFromTab("Root.Settings", "CanViewType"); - $fields->removeFieldFromTab("Root.Settings", "ViewerGroups"); - $fields->removeFieldFromTab("Root.Settings", "CanEditType"); - $fields->removeFieldFromTab("Root.Settings", "EditorGroups"); + if (!$this->owner->config()->get('show_permissions')) { + $fields->removeFieldFromTab("Root.Settings", "CanViewType"); + $fields->removeFieldFromTab("Root.Settings", "ViewerGroups"); + $fields->removeFieldFromTab("Root.Settings", "CanEditType"); + $fields->removeFieldFromTab("Root.Settings", "EditorGroups"); + } } }