diff --git a/code/controllers/CMSPageAddController.php b/code/controllers/CMSPageAddController.php index 14564425..bace5550 100644 --- a/code/controllers/CMSPageAddController.php +++ b/code/controllers/CMSPageAddController.php @@ -10,6 +10,7 @@ class CMSPageAddController extends CMSPageEditController { private static $allowed_actions = array( 'AddForm', 'doAdd', + 'doCancel' ); /** @@ -108,9 +109,11 @@ class CMSPageAddController extends CMSPageEditController { } $actions = new FieldList( - // $resetAction = new ResetFormAction('doCancel', _t('CMSMain.Cancel', 'Cancel')), FormAction::create("doAdd", _t('CMSMain.Create',"Create")) ->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept') + ->setUseButtonTag(true), + FormAction::create("doCancel", _t('CMSMain.Cancel',"Cancel")) + ->addExtraClass('ss-ui-action-destructive ss-ui-action-cancel') ->setUseButtonTag(true) ); @@ -174,4 +177,8 @@ class CMSPageAddController extends CMSPageEditController { return $this->redirect(Controller::join_links(singleton('CMSPageEditController')->Link('show'), $record->ID)); } + public function doCancel($data, $form) { + return $this->redirect(singleton('CMSMain')->Link()); + } + } diff --git a/code/controllers/CMSSettingsController.php b/code/controllers/CMSSettingsController.php index 846a7891..914382b9 100644 --- a/code/controllers/CMSSettingsController.php +++ b/code/controllers/CMSSettingsController.php @@ -77,7 +77,13 @@ class CMSSettingsController extends LeftAndMain { public function save_siteconfig($data, $form) { $siteConfig = SiteConfig::current_site_config(); $form->saveInto($siteConfig); - $siteConfig->write(); + + try { + $siteConfig->write(); + } catch(ValidationException $ex) { + $form->sessionMessage($ex->getResult()->message(), 'bad'); + return $this->getResponseNegotiator()->respond($this->request); + } $this->response->addHeader('X-Status', rawurlencode(_t('LeftAndMain.SAVEDUP', 'Saved.'))); return $this->getResponseNegotiator()->respond($this->request); diff --git a/code/model/ErrorPage.php b/code/model/ErrorPage.php index ac029c7a..e5503ecb 100644 --- a/code/model/ErrorPage.php +++ b/code/model/ErrorPage.php @@ -42,7 +42,9 @@ class ErrorPage extends Page { /** * Get a {@link SS_HTTPResponse} to response to a HTTP error code if an - * {@link ErrorPage} for that code is present. + * {@link ErrorPage} for that code is present. First tries to serve it + * through the standard SilverStripe request method. Falls back to a static + * file generated when the user hit's save and publish in the CMS * * @param int $statusCode * @@ -50,11 +52,17 @@ class ErrorPage extends Page { */ public static function response_for($statusCode) { // first attempt to dynamically generate the error page - if($errorPage = DataObject::get_one('ErrorPage', "\"ErrorPage\".\"ErrorCode\" = $statusCode")) { + $errorPage = ErrorPage::get()->filter(array( + "ErrorCode" => $statusCode + ))->first(); + + if($errorPage) { Requirements::clear(); Requirements::clear_combined_files(); - return ModelAsController::controller_for($errorPage)->handleRequest(new SS_HTTPRequest('GET', ''), DataModel::inst()); + return ModelAsController::controller_for($errorPage)->handleRequest( + new SS_HTTPRequest('GET', ''), DataModel::inst() + ); } // then fall back on a cached version @@ -62,13 +70,13 @@ class ErrorPage extends Page { $statusCode, class_exists('Translatable') ? Translatable::get_current_locale() : null ); - + if(file_exists($cachedPath)) { $response = new SS_HTTPResponse(); $response->setStatusCode($statusCode); $response->setBody(file_get_contents($cachedPath)); - + return $response; } } @@ -129,13 +137,12 @@ class ErrorPage extends Page { } } } - } } /** - * Returns an array of arrays, each of which defines - * properties for a new ErrorPage record. + * Returns an array of arrays, each of which defines properties for a new + * ErrorPage record. * * @return array */ @@ -159,6 +166,7 @@ class ErrorPage extends Page { ) ) ); + $this->extend('getDefaultRecords', $data); return $data; @@ -316,14 +324,20 @@ class ErrorPage extends Page { */ class ErrorPage_Controller extends Page_Controller { - public function init() { - parent::init(); + /** + * Overload the provided {@link Controller::handleRequest()} to append the + * correct status code post request since otherwise permission related error + * pages such as 401 and 403 pages won't be rendered due to + * {@link SS_HTTPResponse::isFinished() ignoring the response body. + * + * @param SS_HTTPRequest + * @param DataModel + */ + public function handleRequest(SS_HTTPRequest $request, DataModel $model = NULL) { + $body = parent::handleRequest($request, $model); + $this->response->setStatusCode($this->ErrorCode); - $action = $this->request->param('Action'); - if(!$action || $action == 'index') { - $this->getResponse()->setStatusCode($this->failover->ErrorCode ? $this->failover->ErrorCode : 404); - } - + return $this->response; } } diff --git a/javascript/CMSMain.AddForm.js b/javascript/CMSMain.AddForm.js index 835c3f86..1668ccff 100644 --- a/javascript/CMSMain.AddForm.js +++ b/javascript/CMSMain.AddForm.js @@ -84,7 +84,7 @@ else $(this).find('input').removeAttr('disabled'); } }); - + $(".cms-page-add-button").entwine({ onclick: function(e) { var tree = $('.cms-tree'), list = $('.cms-list'), parentId = 0; diff --git a/templates/Includes/CMSSettingsController_Content.ss b/templates/Includes/CMSSettingsController_Content.ss index 1bda4c6a..058c52b0 100644 --- a/templates/Includes/CMSSettingsController_Content.ss +++ b/templates/Includes/CMSSettingsController_Content.ss @@ -1,4 +1,4 @@ -