FIX Only add page font icon classes if there's no icon image defined

This commit is contained in:
Guy Marriott 2019-05-08 16:13:33 +12:00
parent 9ab7ae16ac
commit 892a91ae3e
No known key found for this signature in database
GPG Key ID: A80F9ACCB86D3DA7
2 changed files with 17 additions and 3 deletions

View File

@ -43,15 +43,26 @@ class CMSPageAddController extends CMSPageEditController
public function AddForm()
{
$pageTypes = array();
$defaultIcon = Config::inst()->get(SiteTree::class, 'icon_class');
foreach ($this->PageTypes() as $type) {
$class = $type->getField('ClassName');
$icon = Config::inst()->get($class, 'icon_class') ?: $defaultIcon;
// If the icon is the SiteTree default and there's some specific icon being provided by `getPageIconURL`
// then we don't need to add the icon class. Otherwise the class take precedence.
if ($icon === $defaultIcon && !empty(singleton($class)->getPageIconURL())) {
$icon = '';
}
$html = sprintf(
'<span class="page-icon %s class-%s"></span><span class="title">%s</span><span class="form__field-description">%s</span>',
Config::inst()->get($type->getField('ClassName'), 'icon_class'),
Convert::raw2htmlid($type->getField('ClassName')),
$icon,
Convert::raw2htmlid($class),
$type->getField('AddAction'),
$type->getField('Description')
);
$pageTypes[$type->getField('ClassName')] = DBField::create_field('HTMLFragment', $html);
$pageTypes[$class] = DBField::create_field('HTMLFragment', $html);
}
// Ensure generic page type shows on top
if (isset($pageTypes['Page'])) {

View File

@ -31,6 +31,9 @@ class LeftAndMainPageIconsExtension extends Extension
$css = '';
$classes = ClassInfo::subclassesFor(SiteTree::class);
foreach ($classes as $class) {
if (!empty(Config::inst()->get($class, 'icon_class', Config::UNINHERITED))) {
continue;
}
$iconURL = SiteTree::singleton($class)->getPageIconURL();
if ($iconURL) {
$cssClass = Convert::raw2htmlid($class);