From 9d35ff8f9559ae7087ce189880db749fe1569efa Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Tue, 31 Jan 2017 10:56:52 +1300 Subject: [PATCH 1/2] API Remove ViewableData::ThemeDir, update changelog to reflect suggested replacement --- docs/en/04_Changelogs/4.0.0.md | 1 + src/View/ViewableData.php | 23 ----------------------- 2 files changed, 1 insertion(+), 23 deletions(-) diff --git a/docs/en/04_Changelogs/4.0.0.md b/docs/en/04_Changelogs/4.0.0.md index 2e78b427c..a8ee9d134 100644 --- a/docs/en/04_Changelogs/4.0.0.md +++ b/docs/en/04_Changelogs/4.0.0.md @@ -975,6 +975,7 @@ specific functions. [oscarotero/Embed](https://github.com/oscarotero/Embed) as a dependency. * Removed TextParser and BBCodeParser. These are available in an archived module, [silverstripe-archive/bbcodeparser](https://github.com/silverstripe-archive/silverstripe-bbcodeparser) +* Removed `ViewableData::ThemeDir`. Use `ThemeResourceLoader::findThemedResource` in conjunction with `SSViewer::get_themes` instead. #### General and Core Deprecated API diff --git a/src/View/ViewableData.php b/src/View/ViewableData.php index e69787252..e7e9f5107 100644 --- a/src/View/ViewableData.php +++ b/src/View/ViewableData.php @@ -546,29 +546,6 @@ class ViewableData extends Object implements IteratorAggregate return $this; } - /** - * Return the directory if the current active theme (relative to the site root). - * - * This method is useful for things such as accessing theme images from your template without hardcoding the theme - * page - e.g. . - * - * This method should only be used when a theme is currently active. However, it will fall over to the current - * project directory. - * - * @param string $subtheme the subtheme path to get - * @return string - */ - public function ThemeDir($subtheme = null) - { - if (Config::inst()->get('SilverStripe\\View\\SSViewer', 'theme_enabled') - && $theme = Config::inst()->get('SilverStripe\\View\\SSViewer', 'theme') - ) { - return THEMES_DIR . "/$theme" . ($subtheme ? "_$subtheme" : null); - } - - return project(); - } - /** * Get part of the current classes ancestry to be used as a CSS class. * From da3db5ff3a8b788c1fd1ad205343162e50af7352 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Tue, 31 Jan 2017 17:00:13 +1300 Subject: [PATCH 2/2] DOCS Update Requirements to use the ThemeResourceLoader to find themed javascript and CSS --- .../01_Templates/03_Requirements.md | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/docs/en/02_Developer_Guides/01_Templates/03_Requirements.md b/docs/en/02_Developer_Guides/01_Templates/03_Requirements.md index c8d19534d..251362c87 100644 --- a/docs/en/02_Developer_Guides/01_Templates/03_Requirements.md +++ b/docs/en/02_Developer_Guides/01_Templates/03_Requirements.md @@ -211,13 +211,17 @@ and production environments. You can also combine CSS files into a media-specific stylesheets as you would with the `Requirements::css` call - use the third paramter of the `combine_files` function: - :::php - $printStylesheets = array( - "$themeDir/css/print_HomePage.css", - "$themeDir/css/print_Page.css", - ); +```php +$loader = ThemeResourceLoader::instance(); +$themes = SSViewer::get_themes(); - Requirements::combine_files('print.css', $printStylesheets, 'print'); +$printStylesheets = array( + $loader->findThemedCSS('print_HomePage.css', $themes), + $loader->findThemedCSS('print_Page.css', $themes) +); + +Requirements::combine_files('print.css', $printStylesheets, 'print'); +``` By default, all requirements files are flushed (deleted) when ?flush querystring parameter is set. This can be disabled by setting the `Requirements.disable_flush_combined` config to `true`. @@ -232,13 +236,17 @@ the destination location of the resulting combined CSS. You can also add the 'async' and/or 'defer' attributes to combined Javascript files as you would with the `Requirements::javascript` call - use the third paramter of the `combine_files` function: - :::php - $scripts = array( - "$themeDir/javascript/some_script.js", - "$themeDir/javascript/some_other_script.js", - ); +```php +$loader = ThemeResourceLoader::instance(); +$themes = SSViewer::get_themes(); - Requirements::combine_files('scripts.js', $scripts, array('async' => true, 'defer' => true)); +$scripts = array( + $loader->findThemedJavascript('some_script.js', $themes), + $loader->findThemedJavascript('some_other_script.js', $themes) +); + +Requirements::combine_files('scripts.js', $scripts, array('async' => true, 'defer' => true)); +``` ## Clearing assets