2013-07-31 10:30:58 +02:00
|
|
|
<?php
|
2016-07-22 01:32:32 +02:00
|
|
|
|
|
|
|
namespace SilverStripe\CMS\Controllers;
|
|
|
|
|
|
|
|
use Extension;
|
|
|
|
use Requirements;
|
|
|
|
use ClassInfo;
|
|
|
|
use Director;
|
|
|
|
|
2013-07-31 10:30:58 +02:00
|
|
|
/**
|
|
|
|
* Extension to include custom page icons
|
2016-03-08 21:50:55 +01:00
|
|
|
*
|
2013-07-31 10:30:58 +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.
|
2016-03-08 21:50:55 +01:00
|
|
|
*
|
|
|
|
* @return string CSS
|
2013-07-31 10:30:58 +02:00
|
|
|
*/
|
|
|
|
public function generatePageIconsCss() {
|
2016-03-08 21:50:55 +01:00
|
|
|
$css = '';
|
|
|
|
|
2016-07-22 01:32:32 +02:00
|
|
|
$classes = ClassInfo::subclassesFor('SilverStripe\\CMS\\Model\\SiteTree');
|
2013-07-31 10:30:58 +02:00
|
|
|
foreach($classes as $class) {
|
2016-03-08 21:50:55 +01:00
|
|
|
$obj = singleton($class);
|
|
|
|
$iconSpec = $obj->stat('icon');
|
2013-07-31 10:30:58 +02:00
|
|
|
|
2016-08-10 06:08:39 +02:00
|
|
|
if(!$iconSpec) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-07-31 10:30:58 +02:00
|
|
|
|
|
|
|
// 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
|
2016-08-10 06:08:39 +02:00
|
|
|
if(!pathinfo($iconFile, PATHINFO_EXTENSION)) {
|
|
|
|
$iconFile .= '-file.gif';
|
|
|
|
}
|
2013-07-31 10:30:58 +02:00
|
|
|
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
2016-03-08 21:50:55 +01:00
|
|
|
}
|