mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 06:05:56 +00:00
ENHANCEMENT Render page tree icons as stylesheets rather than $_TREE_ICONS JS definitions. Removed file/folder swapping of SiteTree::$icon, use relative file path including extension instead.
This commit is contained in:
parent
023ac994e9
commit
ac79934077
@ -137,13 +137,23 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
|
|||||||
* Return the entire site tree as a nested set of ULs
|
* Return the entire site tree as a nested set of ULs
|
||||||
*/
|
*/
|
||||||
public function SiteTreeAsUL() {
|
public function SiteTreeAsUL() {
|
||||||
$this->generateTreeStylingJS();
|
$html = '';
|
||||||
|
|
||||||
|
// Include custom CSS for tree icons inline, as the tree might be loaded
|
||||||
|
// via Ajax, in which case we can't inject it into the HTML header easily through the HTTP response.
|
||||||
|
$css = $this->generateTreeStylingCSS();
|
||||||
|
if($this->isAjax()) {
|
||||||
|
$html .= "<style type=\"text/css\">\n" . $css . "</style>\n";
|
||||||
|
} else {
|
||||||
|
Requirements::customCSS($css);
|
||||||
|
}
|
||||||
|
|
||||||
// Pre-cache sitetree version numbers for querying efficiency
|
// Pre-cache sitetree version numbers for querying efficiency
|
||||||
Versioned::prepopulate_versionnumber_cache("SiteTree", "Stage");
|
Versioned::prepopulate_versionnumber_cache("SiteTree", "Stage");
|
||||||
Versioned::prepopulate_versionnumber_cache("SiteTree", "Live");
|
Versioned::prepopulate_versionnumber_cache("SiteTree", "Live");
|
||||||
|
$html .= $this->getSiteTreeFor($this->stat('tree_class'));
|
||||||
|
|
||||||
return $this->getSiteTreeFor($this->stat('tree_class'));
|
return $html;
|
||||||
}
|
}
|
||||||
|
|
||||||
function SearchForm() {
|
function SearchForm() {
|
||||||
@ -257,43 +267,52 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
|
|||||||
|
|
||||||
return Convert::raw2xml(Convert::raw2json($def));
|
return Convert::raw2xml(Convert::raw2json($def));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generateTreeStylingJS() {
|
/**
|
||||||
$classes = ClassInfo::subclassesFor($this->stat('tree_class'));
|
* 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
|
||||||
|
*/
|
||||||
|
function generateTreeStylingCSS() {
|
||||||
|
$css = '';
|
||||||
|
|
||||||
|
$classes = ClassInfo::subclassesFor('SiteTree');
|
||||||
foreach($classes as $class) {
|
foreach($classes as $class) {
|
||||||
$obj = singleton($class);
|
$obj = singleton($class);
|
||||||
if($obj instanceof HiddenClass) continue;
|
$iconSpec = $obj->stat('icon');
|
||||||
if($icon = $obj->stat('icon')) $iconInfo[$class] = $icon;
|
|
||||||
}
|
|
||||||
$iconInfo['BrokenLink'] = 'cms/images/treeicons/brokenlink';
|
|
||||||
|
|
||||||
|
if(!$iconSpec) continue;
|
||||||
|
|
||||||
$js = "var _TREE_ICONS = [];\n";
|
// 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';
|
||||||
|
|
||||||
foreach($iconInfo as $class => $icon) {
|
$iconPathInfo = pathinfo($iconFile);
|
||||||
// SiteTree::$icon can be set to array($icon, $option)
|
|
||||||
// $option can be "file" or "folder" to force the icon to always be the file or the folder form
|
// Base filename
|
||||||
$option = null;
|
$baseFilename = $iconPathInfo['dirname'] . '/' . $iconPathInfo['filename'];
|
||||||
if(is_array($icon)) list($icon, $option) = $icon;
|
$fileExtension = $iconPathInfo['extension'];
|
||||||
|
|
||||||
$fileImage = ($option == "folder") ? $icon . '-openfolder.gif' : $icon . '-file.gif';
|
if(Director::fileExists($iconFile)) {
|
||||||
$openFolderImage = $icon . '-openfolder.gif';
|
$css .= sprintf(
|
||||||
if(!Director::fileExists($openFolderImage) || $option == "file") $openFolderImage = $fileImage;
|
"li.class-%s > a .jstree-pageicon { background: transparent url('%s') 0 0 no-repeat; }\n",
|
||||||
$closedFolderImage = $icon . '-closedfolder.gif';
|
$class, $iconFile
|
||||||
if(!Director::fileExists($closedFolderImage) || $option == "file") $closedFolderImage = $fileImage;
|
);
|
||||||
|
} else {
|
||||||
|
// Support for more sophisticated rules, e.g. sprited icons
|
||||||
|
$css .= sprintf(
|
||||||
|
"li.class-%s > a .jstree-pageicon { %s }\n",
|
||||||
|
$class, $iconFile
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$js .= <<<JS
|
|
||||||
_TREE_ICONS['$class'] = {
|
|
||||||
fileIcon: '$fileImage',
|
|
||||||
openFolderIcon: '$openFolderImage',
|
|
||||||
closedFolderIcon: '$closedFolderImage'
|
|
||||||
};
|
|
||||||
|
|
||||||
JS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Requirements::customScript($js);
|
return $css;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -22,8 +22,6 @@ class ErrorPage extends Page {
|
|||||||
"ShowInSearch" => 0
|
"ShowInSearch" => 0
|
||||||
);
|
);
|
||||||
|
|
||||||
static $icon = array("sapphire/javascript/tree/images/page", "file");
|
|
||||||
|
|
||||||
static $description = 'Custom content for different error cases (e.g. "Page not found")';
|
static $description = 'Custom content for different error cases (e.g. "Page not found")';
|
||||||
|
|
||||||
protected static $static_filepath = ASSETS_PATH;
|
protected static $static_filepath = ASSETS_PATH;
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
class RedirectorPage extends Page {
|
class RedirectorPage extends Page {
|
||||||
|
|
||||||
static $icon = array("cms/images/treeicons/page-shortcut","file");
|
static $icon = "cms/images/treeicons/page-shortcut-file.gif";
|
||||||
|
|
||||||
static $description = 'Redirects to a different internal page';
|
static $description = 'Redirects to a different internal page';
|
||||||
|
|
||||||
|
@ -128,21 +128,20 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
|||||||
*/
|
*/
|
||||||
static $can_create = true;
|
static $can_create = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see CMSMain::generateTreeStylingCSS()
|
||||||
|
*/
|
||||||
|
static $page_states = array('readonly');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Icon to use in the CMS
|
* Icon to use in the CMS page tree. This should be the full filename, relative to the webroot.
|
||||||
*
|
* Also supports custom CSS rule contents (applied to the correct selector for the tree UI implementation).
|
||||||
* This should be the base filename. The suffixes -file.gif,
|
*
|
||||||
* -openfolder.gif and -closedfolder.gif will be appended to the base name
|
* @see CMSMain::generateTreeStylingCSS()
|
||||||
* that you provide there.
|
*
|
||||||
* If you prefer, you can pass an array:
|
* @var string
|
||||||
* array("sapphire\javascript\tree\images\page", $option).
|
|
||||||
* $option can be either "file" or "folder" to force the icon to always
|
|
||||||
* be a file or folder, regardless of whether the page has children or not
|
|
||||||
*
|
|
||||||
* @var string|array
|
|
||||||
*/
|
*/
|
||||||
static $icon = array("sapphire/javascript/tree/images/page", "file");
|
static $icon = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var String Description of the class functionality, typically shown to a user
|
* @var String Description of the class functionality, typically shown to a user
|
||||||
@ -150,7 +149,6 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
|||||||
*/
|
*/
|
||||||
static $description = 'Generic content page';
|
static $description = 'Generic content page';
|
||||||
|
|
||||||
|
|
||||||
static $extensions = array(
|
static $extensions = array(
|
||||||
"Hierarchy",
|
"Hierarchy",
|
||||||
"Versioned('Stage', 'Live')",
|
"Versioned('Stage', 'Live')",
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
class VirtualPage extends Page {
|
class VirtualPage extends Page {
|
||||||
|
|
||||||
static $icon = array("cms/images/treeicons/page-shortcut-gold","file");
|
static $icon = "cms/images/treeicons/page-shortcut-gold-file.gif";
|
||||||
|
|
||||||
static $description = 'Displays the content of another page';
|
static $description = 'Displays the content of another page';
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user