-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH Display error messages in admin with an admin context
- Loading branch information
1 parent
f58e4aa
commit 1d56b55
Showing
7 changed files
with
175 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace SilverStripe\Admin; | ||
|
||
use SilverStripe\Control\Controller; | ||
use SilverStripe\Control\Director; | ||
use SilverStripe\Control\HTTPRequest; | ||
use SilverStripe\Core\Extension; | ||
|
||
class AdminErrorExtension extends Extension | ||
{ | ||
/** | ||
* Used by {@see RequestHandler::httpError} | ||
*/ | ||
public function onBeforeHTTPError($statusCode, HTTPRequest $request, $errorMessage = null) | ||
{ | ||
$controller = $this->getAdminController(); | ||
if (!$controller || Director::is_ajax($request)) { | ||
return; | ||
} | ||
$controller->setHttpErrorMessage($errorMessage); | ||
} | ||
|
||
private function getAdminController(): ?Controller | ||
{ | ||
if ($this->owner instanceof LeftAndMain) { | ||
return $this->owner; | ||
} | ||
if (Controller::has_curr() && (Controller::curr() instanceof LeftAndMain)) { | ||
return Controller::curr(); | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
templates/SilverStripe/Admin/Includes/LeftAndMain_Error.ss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<div class="cms-content flexbox-area-grow $BaseCSSClasses" data-layout-type="border" data-pjax-fragment="Content"> | ||
|
||
<div class="cms-content-header north"> | ||
<div class="cms-content-header-info vertical-align-items flexbox-area-grow"> | ||
<div class="breadcrumbs-wrapper"> | ||
<span class="cms-panel-link crumb last"> | ||
$ErrorType | ||
</span> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
$Tools | ||
|
||
<div class="panel panel--padded"> | ||
$Message | ||
<% if $isDev && $HttpErrorMessage %> | ||
<p> | ||
<strong><%t SilverStripe\Admin\LeftAndMain.ErrorDetail "Error detail: {detail}" detail=$HttpErrorMessage %></strong> | ||
</p> | ||
<% end_if %> | ||
</div> | ||
|
||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
@gsat | ||
Feature: Not found | ||
As a site owner | ||
I want error messages to be displayed in the context of the admin section | ||
|
||
Background: | ||
Given I am logged in with "ADMIN" permissions | ||
|
||
Scenario: Errors are displayed in the admin context | ||
Given I go to "/admin/nothing" | ||
Then I should see "Not Found" | ||
And I should see "Sorry, it seems you were trying to access a page that doesn't exist." | ||
And I should see the admin menu | ||
Given I go to "/admin/pages/nothing" | ||
Then I should see "Not Found" | ||
And I should see "Sorry, it seems you were trying to access a page that doesn't exist." | ||
And I should see the admin menu | ||
Given I go to "/admin/security/EditForm/nothing" | ||
Then I should see "Not Found" | ||
And I should see "Sorry, it seems you were trying to access a page that doesn't exist." | ||
And I should see the admin menu | ||
Given I go to "/admin/security/EditForm/field/Members/nothing" | ||
Then I should see "Not Found" | ||
And I should see "Sorry, it seems you were trying to access a page that doesn't exist." | ||
And I should see the admin menu | ||
Given I go to "/admin/settings/nothing" | ||
Then I should see "Not Found" | ||
And I should see "Sorry, it seems you were trying to access a page that doesn't exist." | ||
And I should see the admin menu | ||
|
||
Scenario: Valid routes do not display the error | ||
Given I go to "/admin/settings" | ||
Then I should not see "Not Found" | ||
And I should not see "Sorry, it seems you were trying to access a page that doesn't exist." | ||
And I should see the admin menu | ||
Given I go to "/admin/security/EditForm/field/Members/item/new" | ||
Then I should not see "Not Found" | ||
And I should not see "Sorry, it seems you were trying to access a page that doesn't exist." | ||
And I should see the admin menu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters