Permalink
Browse files

Move CMSMain->generatePageIconsCss() into a LeftAndMain extension (fi…

…xes #798)
  • Loading branch information...
1 parent f937b95 commit 09b869f5d369c8752726a7dcc026a734ba3d9ed7 @kinglozzer kinglozzer committed Jul 31, 2013
Showing with 58 additions and 41 deletions.
  1. +3 −0 _config/config.yml
  2. +0 −41 code/controllers/CMSMain.php
  3. +55 −0 code/controllers/LeftAndMainPageIconsExtension.php
View
@@ -0,0 +1,3 @@
+LeftAndMain:
+ extensions:
+ - LeftAndMainPageIconsExtension
@@ -443,47 +443,6 @@ public function SiteTreeHints() {
}
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
@@ -0,0 +1,55 @@
+<?php
+/**
+ * Extension to include custom page icons
+ *
+ * @package cms
+ * @subpackage controller
+ */
+class LeftAndMainPageIconsExtension extends Extension {
+
+ public function init() {
+ Requirements::customCSS($this->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;
+ }
+
+}

0 comments on commit 09b869f

Please sign in to comment.