-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure the style guide is always accessible to all users
- Loading branch information
Maxime Rainville
committed
Jul 23, 2019
1 parent
dd03af2
commit 126dace
Showing
2 changed files
with
59 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,49 @@ | ||
<?php | ||
|
||
namespace SilverStripe\Controllers; | ||
|
||
use BenManu\SimpleStyleguide\SimpleStyleguideController as BenSimpleStyleguideController; | ||
use SilverStripe\CMS\Controllers\ModelAsController; | ||
use SilverStripe\CMS\Model\SiteTree; | ||
use SilverStripe\View\Requirements; | ||
use SilverStripe\Subsites\Model\Subsite; | ||
|
||
/** | ||
* Overrides `BenManu\SimpleStyleguide\SimpleStyleguideController` so we can allow non-dev users to access the style | ||
* guide. | ||
*/ | ||
class SimpleStyleguideController extends BenSimpleStyleguideController | ||
{ | ||
|
||
private static $url_segment = 'styleguide'; | ||
|
||
/** | ||
* @note This function was copied from BenSimpleStyleguideController. We commented-out the access control logic so | ||
* all users can see the Style guide all the time. | ||
* @return \SilverStripe\ORM\FieldType\DBHTMLText | ||
*/ | ||
public function index() | ||
{ | ||
// This block was in the original SimpleStyleguideController | ||
//if (!Director::isDev() && !Permission::check('ADMIN')) { | ||
// return Security::permissionFailure(); | ||
//} | ||
|
||
// If the subsite module is installed then set the theme based on the current subsite | ||
if (class_exists('Subsite') && Subsite::currentSubsite()) { | ||
Config::inst()->update('SSViewer', 'theme', Subsite::currentSubsite()->Theme); | ||
} | ||
|
||
$page = SiteTree::get()->first(); | ||
$controller = ModelAsController::controller_for($page); | ||
$controller->init(); | ||
|
||
// requirements | ||
Requirements::css('benmanu/silverstripe-simple-styleguide: css/styleguide.css'); | ||
Requirements::javascript('benmanu/silverstripe-simple-styleguide: js/styleguide.js'); | ||
|
||
return $controller | ||
->customise($this->getStyleGuideData()) | ||
->renderWith(['SimpleStyleguideController', 'Page']); | ||
} | ||
} |