From 53d735c4f6091c62c298c5d4c3e0313bedcc2248 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Thu, 15 Oct 2009 22:33:14 +0000 Subject: [PATCH] FEATURE SiteConfig (from r85339) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@89194 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- code/CMSMain.php | 15 ++++++++++++++- code/LeftAndMain.php | 14 +++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/code/CMSMain.php b/code/CMSMain.php index c13672be..2aed6ea6 100755 --- a/code/CMSMain.php +++ b/code/CMSMain.php @@ -351,6 +351,14 @@ JS; return $result; } + function save_siteconfig($data, $form) { + $siteConfig = SiteConfig::current_site_config(); + $form->saveInto($siteConfig); + $siteConfig->write(); + FormResponse::status_message('Saved site configuration', "good"); + FormResponse::add("$('Form_EditForm').resetElements();"); + return FormResponse::respond(); + } /** * Get a database record to be managed by the CMS */ @@ -396,7 +404,7 @@ JS; $fields = $record->getCMSFields($this); if ($fields == null) { - user_error("getCMSFields returned null on a 'Page' object - it should return a FieldSet object. Perhaps you forgot to put a return statement at the end of your method?", E_USER_ERROR); + user_error("getCMSFields returned null on a '".get_class($record)."' object - it should return a FieldSet object. Perhaps you forgot to put a return statement at the end of your method?", E_USER_ERROR); } $fields->push($idField = new HiddenField("ID")); $fields->push($liveURLField = new HiddenField("LiveURLSegment")); @@ -459,6 +467,11 @@ JS; $form->setFields($readonlyFields); } + return $form; + } if ($id == 0) { + $siteConfig = SiteConfig::current_site_config(); + $form = new Form($this, "EditForm", $siteConfig->getFormFields(), $siteConfig->getFormActions()); + $form->loadDataFrom($siteConfig); return $form; } else if($id) { return new Form($this, "EditForm", new FieldSet( diff --git a/code/LeftAndMain.php b/code/LeftAndMain.php index df01c1d8..e657e71f 100644 --- a/code/LeftAndMain.php +++ b/code/LeftAndMain.php @@ -992,12 +992,16 @@ JS; // Include JavaScript to ensure HtmlEditorField works. HtmlEditorField::include_js(); - $record = $this->currentPage(); - if(!$record) return false; + if ($this->currentPageID() != 0) { + $record = $this->currentPage(); + if(!$record) return false; + if($record && !$record->canView()) return Security::permissionFailure($this); + } + if ($this->hasMethod('getEditForm')) { + return $this->getEditForm($this->currentPageID()); + } - if($record && !$record->canView()) return Security::permissionFailure($this); - - return $this->getEditForm($record->ID); + return false; } public function myprofile() {