2013-07-31 09:30:58 +01:00
|
|
|
<?php
|
2016-07-22 11:32:32 +12:00
|
|
|
|
|
|
|
namespace SilverStripe\CMS\Controllers;
|
|
|
|
|
2017-09-20 13:51:07 +12:00
|
|
|
use SilverStripe\CMS\Model\SiteTree;
|
2016-08-23 14:36:06 +12:00
|
|
|
use SilverStripe\Core\ClassInfo;
|
2017-10-18 12:32:08 +13:00
|
|
|
use SilverStripe\Core\Config\Config;
|
|
|
|
use SilverStripe\Core\Convert;
|
2016-08-23 14:36:06 +12:00
|
|
|
use SilverStripe\Core\Extension;
|
2017-10-18 12:32:08 +13:00
|
|
|
use SilverStripe\View\Requirements;
|
2016-07-22 11:32:32 +12:00
|
|
|
|
2013-07-31 09:30:58 +01:00
|
|
|
/**
|
|
|
|
* Extension to include custom page icons
|
|
|
|
*/
|
2017-01-26 09:59:25 +13:00
|
|
|
class LeftAndMainPageIconsExtension extends Extension
|
|
|
|
{
|
|
|
|
|
|
|
|
public function init()
|
|
|
|
{
|
2017-09-07 12:36:26 +12:00
|
|
|
Requirements::customCSS($this->generatePageIconsCss(), CMSMain::PAGE_ICONS_ID);
|
2017-01-26 09:59:25 +13: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 13:51:07 +12:00
|
|
|
$classes = ClassInfo::subclassesFor(SiteTree::class);
|
2017-01-26 09:59:25 +13:00
|
|
|
foreach ($classes as $class) {
|
2019-05-08 16:13:33 +12:00
|
|
|
if (!empty(Config::inst()->get($class, 'icon_class', Config::UNINHERITED))) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-10-18 12:32:08 +13:00
|
|
|
$iconURL = SiteTree::singleton($class)->getPageIconURL();
|
|
|
|
if ($iconURL) {
|
2017-11-22 19:55:35 +00:00
|
|
|
$cssClass = Convert::raw2htmlid($class);
|
|
|
|
$selector = sprintf('.page-icon.class-%1$s, li.class-%1$s > a .jstree-pageicon', $cssClass);
|
|
|
|
$css .= sprintf('%s { background: transparent url(\'%s\') 0 0 no-repeat; }', $selector, $iconURL);
|
2017-01-26 09:59:25 +13:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $css;
|
|
|
|
}
|
2016-03-09 09:50:55 +13:00
|
|
|
}
|