silverstripe-cms/code/Controllers/LeftAndMainPageIconsExtension.php

51 lines
1.4 KiB
PHP
Raw Normal View History

<?php
2016-07-22 01:32:32 +02:00
namespace SilverStripe\CMS\Controllers;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Core\ClassInfo;
2017-10-18 01:32:08 +02:00
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Convert;
use SilverStripe\Core\Extension;
2017-10-18 01:32:08 +02:00
use SilverStripe\View\Requirements;
2016-07-22 01:32:32 +02:00
/**
* Extension to include custom page icons
*/
2017-01-25 21:59:25 +01:00
class LeftAndMainPageIconsExtension extends Extension
{
public function init()
{
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 = '';
$classes = ClassInfo::subclassesFor(SiteTree::class);
2017-01-25 21:59:25 +01:00
foreach ($classes as $class) {
2017-10-18 01:32:08 +02:00
$icon = Config::inst()->get($class, 'icon');
if (!$icon) {
2017-01-25 21:59:25 +01:00
continue;
}
2017-10-18 01:32:08 +02:00
$cssClass = Convert::raw2htmlid($class);
$selector = ".page-icon.class-$cssClass, li.class-$cssClass > a .jstree-pageicon";
$iconURL = SiteTree::singleton($class)->getPageIconURL();
if ($iconURL) {
$css .= "$selector { background: transparent url('$iconURL') 0 0 no-repeat; }\n";
2017-01-25 21:59:25 +01:00
}
}
return $css;
}
2016-03-08 21:50:55 +01:00
}