From 7f91feea4fb0bb3ad6482122df0c2ed1137164ff Mon Sep 17 00:00:00 2001 From: Nathan Glasl Date: Wed, 27 Jan 2016 16:28:36 +1100 Subject: [PATCH] Correcting a minor issue when determining a page not found. --- README.md | 2 +- code/pages/MediaHolder.php | 39 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 246eb37..48b5874 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # [mediawesome](https://packagist.org/packages/nglasl/silverstripe-mediawesome) -_The current release is **1.1.8**_ +_The current release is **1.1.9**_ A module for SilverStripe which will allow creation of dynamic media holders/pages with CMS customisable types and attributes (blogs, events, news, publications). diff --git a/code/pages/MediaHolder.php b/code/pages/MediaHolder.php index c9ce313..11667d7 100644 --- a/code/pages/MediaHolder.php +++ b/code/pages/MediaHolder.php @@ -130,6 +130,45 @@ public function index() { return $this->renderWith($templates); } + /** + * Display an error page on invalid request. + * + * @parameter <{ERROR_CODE}> integer + * @parameter <{ERROR_MESSAGE}> string + */ + + public function httpError($code, $message = null) { + + // Determine the error page for the given status code. + + $errorPages = ErrorPage::get()->filter('ErrorCode', $code); + + // Allow extension customisation. + + $this->extend('updateErrorPages', $errorPages); + + // Retrieve the error page response. + + if($errorPage = $errorPages->first()) { + Requirements::clear(); + Requirements::clear_combined_files(); + $response = ModelAsController::controller_for($errorPage)->handleRequest(new SS_HTTPRequest('GET', ''), DataModel::inst()); + throw new SS_HTTPResponse_Exception($response, $code); + } + + // Retrieve the cached error page response. + + else if(file_exists($cachedPage = ErrorPage::get_filepath_for_errorcode($code, class_exists('Translatable') ? Translatable::get_current_locale() : null))) { + $response = new SS_HTTPResponse(); + $response->setStatusCode($code); + $response->setBody(file_get_contents($cachedPage)); + throw new SS_HTTPResponse_Exception($response, $code); + } + else { + return parent::httpError($code, $message); + } + } + /** * Retrieve a paginated list of media holder/page children for your template, with optional date/tag filters parsed from the GET request. *