Support abort(404) in the backend module

This commit is contained in:
Luke Towers 2019-02-21 10:44:58 -06:00
parent 8a60d3c19a
commit d6f8cc179d

View File

@ -4,6 +4,7 @@ use Str;
use App;
use File;
use View;
use Event;
use Config;
use Response;
use Illuminate\Routing\Controller as ControllerBase;
@ -44,6 +45,11 @@ class BackendController extends ControllerBase
*/
public static $params;
/**
* @var boolean Flag to indicate that the CMS module is handling the current request
*/
protected $cmsHandling = false;
/**
* Instantiate a new BackendController instance.
*/
@ -69,6 +75,7 @@ class BackendController extends ControllerBase
protected function passToCmsController($url)
{
if (class_exists('\Cms\Classes\Controller')) {
$this->cmsHandling = true;
return App::make('Cms\Classes\Controller')->run($url);
} else {
return Response::make(View::make('backend::404'), 404);
@ -87,6 +94,13 @@ class BackendController extends ControllerBase
{
$params = RouterHelper::segmentizeUrl($url);
// Handle NotFoundHttpExceptions in the backend (usually triggered by abort(404))
Event::listen('exception.beforeRender', function ($exception, $httpCode, $request) {
if (!$this->cmsHandling && $exception instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException) {
return View::make('backend::404');
}
}, 1);
/*
* Database check
*/
@ -189,4 +203,4 @@ class BackendController extends ControllerBase
return $actionName;
}
}
}