From 09b869f5d369c8752726a7dcc026a734ba3d9ed7 Mon Sep 17 00:00:00 2001 From: Loz Calver Date: Wed, 31 Jul 2013 09:30:58 +0100 Subject: [PATCH] Move CMSMain->generatePageIconsCss() into a LeftAndMain extension (fixes #798) --- _config/config.yml | 3 + code/controllers/CMSMain.php | 41 -------------- .../LeftAndMainPageIconsExtension.php | 55 +++++++++++++++++++ 3 files changed, 58 insertions(+), 41 deletions(-) create mode 100644 _config/config.yml create mode 100644 code/controllers/LeftAndMainPageIconsExtension.php diff --git a/_config/config.yml b/_config/config.yml new file mode 100644 index 00000000..b1b1fd8e --- /dev/null +++ b/_config/config.yml @@ -0,0 +1,3 @@ +LeftAndMain: + extensions: + - LeftAndMainPageIconsExtension \ No newline at end of file diff --git a/code/controllers/CMSMain.php b/code/controllers/CMSMain.php index c7ae441c..5c83cb40 100644 --- a/code/controllers/CMSMain.php +++ b/code/controllers/CMSMain.php @@ -443,47 +443,6 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr } return $json; } - - /** - * Include CSS for page icons. We're not using the JSTree 'types' option - * because it causes too much performance overhead just to add some icons. - * - * @return String CSS - */ - public function generatePageIconsCss() { - $css = ''; - - $classes = ClassInfo::subclassesFor('SiteTree'); - foreach($classes as $class) { - $obj = singleton($class); - $iconSpec = $obj->stat('icon'); - - if(!$iconSpec) continue; - - // Legacy support: We no longer need separate icon definitions for folders etc. - $iconFile = (is_array($iconSpec)) ? $iconSpec[0] : $iconSpec; - - // Legacy support: Add file extension if none exists - if(!pathinfo($iconFile, PATHINFO_EXTENSION)) $iconFile .= '-file.gif'; - - $iconPathInfo = pathinfo($iconFile); - - // Base filename - $baseFilename = $iconPathInfo['dirname'] . '/' . $iconPathInfo['filename']; - $fileExtension = $iconPathInfo['extension']; - - $selector = ".page-icon.class-$class, li.class-$class > a .jstree-pageicon"; - - if(Director::fileExists($iconFile)) { - $css .= "$selector { background: transparent url('$iconFile') 0 0 no-repeat; }\n"; - } else { - // Support for more sophisticated rules, e.g. sprited icons - $css .= "$selector { $iconFile }\n"; - } - } - - return $css; - } /** * Populates an array of classes in the CMS diff --git a/code/controllers/LeftAndMainPageIconsExtension.php b/code/controllers/LeftAndMainPageIconsExtension.php new file mode 100644 index 00000000..5b481d7d --- /dev/null +++ b/code/controllers/LeftAndMainPageIconsExtension.php @@ -0,0 +1,55 @@ +generatePageIconsCss()); + } + + /** + * Include CSS for page icons. We're not using the JSTree 'types' option + * because it causes too much performance overhead just to add some icons. + * + * @return String CSS + */ + public function generatePageIconsCss() { + $css = ''; + + $classes = ClassInfo::subclassesFor('SiteTree'); + foreach($classes as $class) { + $obj = singleton($class); + $iconSpec = $obj->stat('icon'); + + if(!$iconSpec) continue; + + // Legacy support: We no longer need separate icon definitions for folders etc. + $iconFile = (is_array($iconSpec)) ? $iconSpec[0] : $iconSpec; + + // Legacy support: Add file extension if none exists + if(!pathinfo($iconFile, PATHINFO_EXTENSION)) $iconFile .= '-file.gif'; + + $iconPathInfo = pathinfo($iconFile); + + // Base filename + $baseFilename = $iconPathInfo['dirname'] . '/' . $iconPathInfo['filename']; + $fileExtension = $iconPathInfo['extension']; + + $selector = ".page-icon.class-$class, li.class-$class > a .jstree-pageicon"; + + if(Director::fileExists($iconFile)) { + $css .= "$selector { background: transparent url('$iconFile') 0 0 no-repeat; }\n"; + } else { + // Support for more sophisticated rules, e.g. sprited icons + $css .= "$selector { $iconFile }\n"; + } + } + + return $css; + } + +} \ No newline at end of file