silverstripe-cms/code/controllers/LeftAndMainPageIconsExtension.php

55 lines
1.5 KiB
PHP
Raw Normal View History

<?php
/**
* Extension to include custom page icons
2015-09-29 06:18:03 +02:00
*
* @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.
2015-09-29 06:18:03 +02:00
*
* @return String CSS
*/
public function generatePageIconsCss() {
2015-09-29 06:18:03 +02:00
$css = '';
$classes = ClassInfo::subclassesFor('SiteTree');
foreach($classes as $class) {
2015-09-29 06:18:03 +02:00
$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';
2015-09-29 06:18:03 +02:00
$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;
}
}