2013-07-31 10:30:58 +02:00
|
|
|
<?php
|
2016-07-22 01:32:32 +02:00
|
|
|
|
|
|
|
namespace SilverStripe\CMS\Controllers;
|
|
|
|
|
2017-09-20 03:51:07 +02:00
|
|
|
use SilverStripe\CMS\Model\SiteTree;
|
2017-08-24 11:39:25 +02:00
|
|
|
use SilverStripe\Core\Convert;
|
2016-08-23 04:36:06 +02:00
|
|
|
use SilverStripe\View\Requirements;
|
|
|
|
use SilverStripe\Core\ClassInfo;
|
|
|
|
use SilverStripe\Control\Director;
|
|
|
|
use SilverStripe\Core\Extension;
|
2016-07-22 01:32:32 +02:00
|
|
|
|
2013-07-31 10:30:58 +02:00
|
|
|
/**
|
|
|
|
* Extension to include custom page icons
|
|
|
|
*/
|
2017-01-25 21:59:25 +01:00
|
|
|
class LeftAndMainPageIconsExtension extends Extension
|
|
|
|
{
|
|
|
|
|
|
|
|
public function init()
|
|
|
|
{
|
2017-09-07 02:36:26 +02:00
|
|
|
Requirements::customCSS($this->generatePageIconsCss(), CMSMain::PAGE_ICONS_ID);
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 = '';
|
|
|
|
|
2017-09-20 03:51:07 +02:00
|
|
|
$classes = ClassInfo::subclassesFor(SiteTree::class);
|
2017-01-25 21:59:25 +01:00
|
|
|
foreach ($classes as $class) {
|
|
|
|
$obj = singleton($class);
|
2017-08-22 23:46:46 +02:00
|
|
|
$iconSpec = $obj->config()->get('icon');
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
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';
|
|
|
|
}
|
|
|
|
|
2017-08-24 11:39:25 +02:00
|
|
|
$class = Convert::raw2htmlid($class);
|
2017-01-25 21:59:25 +01: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
|
|
|
}
|