Skip to content

Commit

Permalink
Merge pull request #39 from open-sausages/pulls/patch-style-guide
Browse files Browse the repository at this point in the history
Make sure the style guide is always accessible to all users
  • Loading branch information
chillu authored Jul 25, 2019
2 parents e2707d3 + e5aa5f8 commit b20e4e6
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/_config/theme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,13 @@ SilverStripe\LoginForms\EnablerExtension:
- '$default'
- 'bambusa'
- 'starter'

---
Name: bambusa-simplestyleguide
After: '#simplestyleguide'
---
# Move the style guide on a different URL segment
SilverStripe\Control\Director:
rules:
'_styleguide': '->styleguide'
'styleguide': SilverStripe\Controllers\SimpleStyleguideController
49 changes: 49 additions & 0 deletions app/src/Controllers/SimpleStyleguideController.php
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::singleton();
$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']);
}
}

0 comments on commit b20e4e6

Please sign in to comment.