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. *