Skip to content

Commit

Permalink
Merge pull request #5830 from open-sausages/pulls/4.0/nested-themes-f…
Browse files Browse the repository at this point in the history
…ixes

API Abstract ThemeManifest into ThemeList
  • Loading branch information
Hamish Friedlander committed Jul 21, 2016
2 parents f548ddf + 20daf1f commit 46b15a9
Show file tree
Hide file tree
Showing 25 changed files with 414 additions and 221 deletions.
38 changes: 9 additions & 29 deletions admin/code/LeftAndMain.php
Expand Up @@ -20,7 +20,7 @@
use SilverStripe\Security\Permission;
use SilverStripe\Security\Security;
use SilverStripe\Security\PermissionProvider;

use SilverStripe\View\ThemeResourceLoader;


/**
Expand Down Expand Up @@ -408,7 +408,8 @@ protected function init() {
&& $candidate->MenuItem->controller
&& singleton($candidate->MenuItem->controller)->canView()
) {
return $this->redirect($candidate->Link);
$this->redirect($candidate->Link);
return;
}
}

Expand All @@ -434,11 +435,14 @@ protected function init() {
),
);

return Security::permissionFailure($this, $messageSet);
Security::permissionFailure($this, $messageSet);
return;
}

// Don't continue if there's already been a redirection request.
if($this->redirectedTo()) return;
if($this->redirectedTo()) {
return;
}

// Audit logging hook
if(empty($_REQUEST['executeForm']) && !$this->getRequest()->isAjax()) $this->extend('accessedCMS');
Expand All @@ -452,29 +456,6 @@ protected function init() {
// file because insufficient information exists when that is being processed
$htmlEditorConfig = HTMLEditorConfig::get_active();
$htmlEditorConfig->setOption('language', i18n::get_tinymce_lang());
if(!$htmlEditorConfig->getOption('content_css')) {
$cssFiles = array();
$cssFiles[] = FRAMEWORK_ADMIN_DIR . '/client/dist/styles/editor.css';

// Use theme from the site config
if(class_exists('SiteConfig') && ($config = SiteConfig::current_site_config()) && $config->Theme) {
$theme = $config->Theme;
} elseif(Config::inst()->get('SSViewer', 'theme_enabled') && Config::inst()->get('SSViewer', 'theme')) {
$theme = Config::inst()->get('SSViewer', 'theme');
} else {
$theme = false;
}

if($theme) $cssFiles[] = THEMES_DIR . "/{$theme}/css/editor.css";
else if(project()) $cssFiles[] = project() . '/css/editor.css';

// Remove files that don't exist
foreach($cssFiles as $k => $cssFile) {
if(!file_exists(BASE_PATH . '/' . $cssFile)) unset($cssFiles[$k]);
}

$htmlEditorConfig->setOption('content_css', implode(',', $cssFiles));
}

Requirements::customScript("
window.ss = window.ss || {};
Expand Down Expand Up @@ -1713,9 +1694,8 @@ public function getSilverStripeNavigator() {
if($page) {
$navigator = new SilverStripeNavigator($page);
return $navigator->renderWith($this->getTemplatesWithSuffix('_SilverStripeNavigator'));
} else {
return false;
}
return null;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions core/Core.php
Expand Up @@ -77,7 +77,7 @@
require_once 'core/manifest/ConfigStaticManifest.php';
require_once 'core/manifest/ClassManifest.php';
require_once 'core/manifest/ManifestFileFinder.php';
require_once 'view/TemplateLoader.php';
require_once 'view/ThemeResourceLoader.php';
require_once 'core/manifest/TokenisedRegularExpression.php';
require_once 'control/injector/Injector.php';

Expand Down Expand Up @@ -112,7 +112,7 @@
Config::inst()->pushConfigYamlManifest($configManifest);

// Load template manifest
SilverStripe\View\TemplateLoader::instance()->addSet('$default', new SilverStripe\View\ThemeManifest(
SilverStripe\View\ThemeResourceLoader::instance()->addSet('$default', new SilverStripe\View\ThemeManifest(
BASE_PATH, project(), false, $flush
));

Expand Down
4 changes: 2 additions & 2 deletions dev/SapphireTest.php
Expand Up @@ -13,7 +13,7 @@
use SilverStripe\Security\Security;
use SilverStripe\Security\Group;
use SilverStripe\Security\Permission;
use SilverStripe\View\TemplateLoader;
use SilverStripe\View\ThemeResourceLoader;
use SilverStripe\View\ThemeManifest;

/**
Expand Down Expand Up @@ -848,7 +848,7 @@ public static function use_test_manifest() {
SS_ClassLoader::instance()->pushManifest($classManifest, false);
SapphireTest::set_test_class_manifest($classManifest);

TemplateLoader::instance()->addSet('$default', new ThemeManifest(
ThemeResourceLoader::instance()->addSet('$default', new ThemeManifest(
BASE_PATH, project(), true, $flush
));

Expand Down
2 changes: 2 additions & 0 deletions docs/en/04_Changelogs/4.0.0.md
Expand Up @@ -51,6 +51,8 @@
a shorthand substitute.
* `FormField->dontEscape` has been removed. Escaping is now managed on a class by class basis.
* `DBString->LimitWordCountXML` removed. Use `LimitWordCount` for XML safe version.
* `$module` parameter in `themedCSS` and `themedJavascript` removed.
* Theme selector has been removed from SiteConfig. Please use `SSViewer.themes` config instead.

## New API

Expand Down
24 changes: 8 additions & 16 deletions forms/htmleditor/TinyMCEConfig.php
@@ -1,6 +1,6 @@
<?php

use SilverStripe\View\TemplateLoader;
use SilverStripe\View\ThemeResourceLoader;

/**
* Default configuration for HtmlEditor specific to tinymce
Expand Down Expand Up @@ -417,24 +417,16 @@ protected function getConfig() {
*/
protected function getEditorCSS() {
$editor = array();
$editor[] = Controller::join_links(
Director::absoluteBaseURL(),
FRAMEWORK_ADMIN_DIR . '/client/dist/styles/editor.css'
);

foreach(SSViewer::get_themes() as $theme) {
$path = TemplateLoader::instance()->getPath($theme);
$editorDir = $path . '/css/editor.css';;

if(file_exists(BASE_PATH . '/' . $editorDir)) {
$editor[] = Controller::join_links(
Director::absoluteBaseURL(),
$editorDir
);
// Add standard editor.css
$editor[] = Director::absoluteURL(FRAMEWORK_ADMIN_DIR . '/client/dist/styles/editor.css');

break;
}
// Themed editor.css
$themedEditor = ThemeResourceLoader::instance()->findThemedCSS('editor', SSViewer::get_themes());
if($themedEditor) {
$editor[] = Director::absoluteURL($themedEditor, Director::BASE);
}

return $editor;
}

Expand Down
@@ -1,6 +1,6 @@
<?php

use SilverStripe\View\TemplateLoader;
use SilverStripe\View\ThemeResourceLoader;
use SilverStripe\View\ThemeManifest;

/**
Expand All @@ -9,7 +9,7 @@
* @package framework
* @subpackage tests
*/
class TemplateLoaderTest extends SapphireTest {
class ThemeResourceLoaderTest extends SapphireTest {

private $base;

Expand All @@ -19,7 +19,7 @@ class TemplateLoaderTest extends SapphireTest {
private $manifest;

/**
* @var TemplateLoader
* @var ThemeResourceLoader
*/
private $loader;

Expand All @@ -28,12 +28,13 @@ class TemplateLoaderTest extends SapphireTest {
*/
public function setUp() {
parent::setUp();

// Fake project root
$this->base = dirname(__FILE__) . '/fixtures/templatemanifest';
// New ThemeManifest for that root
$this->manifest = new ThemeManifest($this->base, 'myproject', false, true);
// New Loader for that root
$this->loader = new TemplateLoader($this->base);
$this->loader = new ThemeResourceLoader($this->base);
$this->loader->addSet('$default', $this->manifest);
}

Expand Down Expand Up @@ -128,6 +129,58 @@ public function testFindTemplatesMainThemeLayoutModule() {
);
}

public function testFindThemedCSS() {
$this->assertEquals(
"myproject/css/project.css",
$this->loader->findThemedCSS('project', ['$default', 'theme'])
);
$this->assertEquals(
"themes/theme/css/project.css",
$this->loader->findThemedCSS('project', ['theme', '$default'])
);
$this->assertEmpty(
$this->loader->findThemedCSS('nofile', ['theme', '$default'])
);
$this->assertEquals(
'module/css/content.css',
$this->loader->findThemedCSS('content', ['/module', 'theme'])
);
$this->assertEquals(
'module/css/content.css',
$this->loader->findThemedCSS('content', ['/module', 'theme', '$default'])
);
$this->assertEquals(
'module/css/content.css',
$this->loader->findThemedCSS('content', ['$default', '/module', 'theme'])
);
}

public function testFindThemedJavascript() {
$this->assertEquals(
"myproject/javascript/project.js",
$this->loader->findThemedJavascript('project', ['$default', 'theme'])
);
$this->assertEquals(
"themes/theme/javascript/project.js",
$this->loader->findThemedJavascript('project', ['theme', '$default'])
);
$this->assertEmpty(
$this->loader->findThemedJavascript('nofile', ['theme', '$default'])
);
$this->assertEquals(
'module/javascript/content.js',
$this->loader->findThemedJavascript('content', ['/module', 'theme'])
);
$this->assertEquals(
'module/javascript/content.js',
$this->loader->findThemedJavascript('content', ['/module', 'theme', '$default'])
);
$this->assertEquals(
'module/javascript/content.js',
$this->loader->findThemedJavascript('content', ['$default', '/module', 'theme'])
);
}

protected function createTestTemplates($templates) {
foreach ($templates as $template) {
file_put_contents($template, '');
Expand Down
@@ -0,0 +1,3 @@
.class {
display: block;
}
@@ -0,0 +1,3 @@
.class {
display: block;
}
@@ -0,0 +1 @@
var i = 0;
@@ -0,0 +1 @@
var i = 0;
@@ -0,0 +1,3 @@
.class {
display: block;
}
@@ -0,0 +1 @@
var i = 0;
@@ -0,0 +1,3 @@
.class {
display: block;
}
@@ -0,0 +1,3 @@
.class {
display: block;
}
@@ -0,0 +1 @@
var i = 0;
@@ -0,0 +1 @@
var i = 0;

0 comments on commit 46b15a9

Please sign in to comment.