diff --git a/code/SiteConfig.php b/code/SiteConfig.php index 99ab4e0a2..b1886e757 100644 --- a/code/SiteConfig.php +++ b/code/SiteConfig.php @@ -2,12 +2,9 @@ namespace SilverStripe\SiteConfig; -use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Forms\FieldList; -use SilverStripe\Forms\FormAction; use SilverStripe\Forms\HiddenField; use SilverStripe\Forms\ListboxField; -use SilverStripe\Forms\LiteralField; use SilverStripe\Forms\OptionsetField; use SilverStripe\Forms\Tab; use SilverStripe\Forms\TabSet; @@ -21,7 +18,6 @@ use SilverStripe\Security\PermissionProvider; use SilverStripe\Security\Security; use SilverStripe\View\TemplateGlobalProvider; -use SilverStripe\CMS\Controllers\CMSMain; use SilverStripe\Forms\SearchableMultiDropdownField; use SilverStripe\Security\InheritedPermissions; @@ -284,31 +280,6 @@ public function getCMSFields() return $fields; } - /** - * Get the actions that are sent to the CMS. - * - * In your extensions: updateEditFormActions($actions) - * - * @return FieldList - */ - public function getCMSActions() - { - if (Permission::check('ADMIN') || Permission::check('EDIT_SITECONFIG')) { - $actions = FieldList::create( - FormAction::create( - 'save_siteconfig', - _t('SilverStripe\\CMS\\Controllers\\CMSMain.SAVE', 'Save') - )->addExtraClass('btn-primary font-icon-save') - ); - } else { - $actions = FieldList::create(); - } - - $this->extend('updateCMSActions', $actions); - - return $actions; - } - public function CMSEditLink(): ?string { return SiteConfigLeftAndMain::singleton()->Link(); @@ -317,18 +288,13 @@ public function CMSEditLink(): ?string /** * Get the current sites SiteConfig, and creates a new one through * {@link make_site_config()} if none is found. - * - * @return SiteConfig */ - public static function current_site_config() + public static function current_site_config(): SiteConfig { $siteConfig = DataObject::get_one(SiteConfig::class); if (!$siteConfig) { $siteConfig = SiteConfig::make_site_config(); } - - static::singleton()->extend('updateCurrentSiteConfig', $siteConfig); - return $siteConfig; } @@ -490,6 +456,15 @@ public function canEdit($member = null) return Permission::checkMember($member, "EDIT_SITECONFIG"); } + public function canDelete($member = null) + { + $extended = $this->extendedCan(__FUNCTION__, $member); + if ($extended !== null) { + return $extended; + } + return false; + } + /** * @return array */ diff --git a/code/SiteConfigLeftAndMain.php b/code/SiteConfigLeftAndMain.php index 84179c3a1..dea1a424e 100644 --- a/code/SiteConfigLeftAndMain.php +++ b/code/SiteConfigLeftAndMain.php @@ -2,179 +2,32 @@ namespace SilverStripe\SiteConfig; -use SilverStripe\Admin\LeftAndMain; +use SilverStripe\Admin\SingleRecordAdmin; use SilverStripe\CMS\Model\SiteTree; -use SilverStripe\Control\Director; -use SilverStripe\Dev\Deprecation; -use SilverStripe\Forms\Form; -use SilverStripe\Forms\FormAction; -use SilverStripe\Forms\HiddenField; -use SilverStripe\Forms\LiteralField; -use SilverStripe\Model\List\ArrayList; -use SilverStripe\ORM\CMSPreviewable; -use SilverStripe\ORM\DataObject; -use SilverStripe\Core\Validation\ValidationResult; -use SilverStripe\Versioned\RecursivePublishable; -use SilverStripe\Model\ArrayData; use SilverStripe\View\Requirements; -class SiteConfigLeftAndMain extends LeftAndMain +class SiteConfigLeftAndMain extends SingleRecordAdmin { - /** - * @var string - */ - private static $url_segment = 'settings'; + private static string $url_segment = 'settings'; - /** - * @var string - */ - private static $url_rule = '/$Action/$ID/$OtherID'; + private static int $menu_priority = -1; - /** - * @var int - */ - private static $menu_priority = -1; + private static string $menu_title = 'Settings'; - /** - * @var string - */ - private static $menu_title = 'Settings'; + private static string $menu_icon_class = 'font-icon-cog'; - /** - * @var string - */ - private static $menu_icon_class = 'font-icon-cog'; + private static string $model_class = SiteConfig::class; - /** - * @var string - * @deprecated 5.4.0 Will be renamed to model_class - */ - private static $tree_class = SiteConfig::class; + private static array $required_permission_codes = [ + 'EDIT_SITECONFIG', + ]; - /** - * @var array - */ - private static $required_permission_codes = array('EDIT_SITECONFIG'); - - /** - * Initialises the {@link SiteConfig} controller. - */ public function init() { parent::init(); + // Add JS required for some aspects of the access tab if (class_exists(SiteTree::class)) { Requirements::javascript('silverstripe/cms: client/dist/js/bundle.js'); } } - - /** - * @param null $id Not used. - * @param null $fields Not used. - * - * @return Form - */ - public function getEditForm($id = null, $fields = null) - { - $siteConfig = SiteConfig::current_site_config(); - $fields = $siteConfig->getCMSFields(); - - // Tell the CMS what URL the preview should show - $home = Director::absoluteBaseURL(); - $fields->push(new HiddenField('PreviewURL', 'Preview URL', $home)); - - if ($siteConfig instanceof CMSPreviewable || $siteConfig->has_extension(CMSPreviewable::class)) { - // Added in-line to the form, but plucked into different view by LeftAndMain.Preview.js upon load - $fields->push($navField = new LiteralField( - 'SilverStripeNavigator', - $this->getSilverStripeNavigator($siteConfig) - )); - $navField->setAllowHTML(true); - } - - $validator = $siteConfig->getCMSCompositeValidator(); - - $actions = $siteConfig->getCMSActions(); - $negotiator = $this->getResponseNegotiator(); - $form = Form::create( - $this, - 'EditForm', - $fields, - $actions, - $validator - )->setHTMLID('Form_EditForm'); - $form->setValidationResponseCallback(function (ValidationResult $errors) use ($negotiator, $form) { - $request = $this->getRequest(); - if ($request->isAjax() && $negotiator) { - $result = $form->forTemplate(); - return $negotiator->respond($request, array( - 'CurrentForm' => function () use ($result) { - return $result; - } - )); - } - }); - $form->addExtraClass('flexbox-area-grow fill-height cms-content cms-edit-form'); - $form->setAttribute('data-pjax-fragment', 'CurrentForm'); - - if ($form->Fields()->hasTabSet()) { - $form->Fields()->findOrMakeTab('Root')->setTemplate('SilverStripe\\Forms\\CMSTabSet'); - } - $form->setHTMLID('Form_EditForm'); - $form->loadDataFrom($siteConfig); - $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); - - - // Announce the capability so the frontend can decide whether to allow preview or not. - if ($siteConfig instanceof CMSPreviewable || $siteConfig->has_extension(CMSPreviewable::class)) { - $form->addExtraClass('cms-previewable'); - } - - // Use