mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-19 07:56:38 +02:00
d52db0ba34
# Conflicts: # .travis.yml # admin/css/ie7.css # admin/css/ie7.css.map # admin/css/ie8.css.map # admin/css/screen.css # admin/css/screen.css.map # admin/javascript/LeftAndMain.js # admin/scss/_style.scss # admin/scss/_uitheme.scss # control/HTTPRequest.php # core/Object.php # css/AssetUploadField.css # css/AssetUploadField.css.map # css/ConfirmedPasswordField.css.map # css/Form.css.map # css/GridField.css.map # css/TreeDropdownField.css.map # css/UploadField.css # css/UploadField.css.map # css/debug.css.map # dev/Debug.php # docs/en/00_Getting_Started/00_Server_Requirements.md # docs/en/02_Developer_Guides/06_Testing/00_Unit_Testing.md # docs/en/02_Developer_Guides/06_Testing/index.md # docs/en/02_Developer_Guides/14_Files/02_Images.md # docs/en/02_Developer_Guides/15_Customising_the_Admin_Interface/How_Tos/Extend_CMS_Interface.md # filesystem/File.php # filesystem/Folder.php # filesystem/GD.php # filesystem/Upload.php # forms/ToggleField.php # forms/Validator.php # javascript/lang/en_GB.js # javascript/lang/fr.js # javascript/lang/src/en.js # javascript/lang/src/fr.js # model/Image.php # model/UnsavedRelationList.php # model/Versioned.php # model/connect/MySQLDatabase.php # model/fieldtypes/DBField.php # model/fieldtypes/Enum.php # scss/AssetUploadField.scss # scss/UploadField.scss # templates/email/ChangePasswordEmail.ss # templates/forms/DropdownField.ss # tests/behat/features/bootstrap/SilverStripe/Framework/Test/Behaviour/CmsFormsContext.php # tests/behat/features/bootstrap/SilverStripe/Framework/Test/Behaviour/CmsUiContext.php # tests/forms/EnumFieldTest.php # tests/security/MemberTest.php # tests/security/MemberTest.yml # tests/security/SecurityTest.php
82 lines
3.5 KiB
Markdown
82 lines
3.5 KiB
Markdown
# How to customise the CMS tree
|
|
|
|
## Overview
|
|
|
|
The CMS tree for viewing hierarchical structures (mostly pages) is powered
|
|
by the [jstree](http://jstree.com) library. It is configured through
|
|
`framework/admin/javascript/src/LeftAndMain.Tree.js`, as well as some
|
|
HTML5 metadata generated on its container (see the `data-hints` attribute).
|
|
|
|
The tree is rendered through [api:LeftAndMain::getSiteTreeFor()],
|
|
which recursively collects all nodes based on various filtering criteria.
|
|
The node strictly just has to implement the [api:Hierarchy] extension,
|
|
but in the CMS usually is a [api:SiteTree] object.
|
|
|
|
## Add status lozenges to tree nodes
|
|
|
|
A tree node in CMS could be rendered with lot of extra information but a node title, such as a
|
|
link that wraps around the node title, a node's id which is given as id attribute of the node
|
|
<li> tag, a extra checkbox beside the tree title, tree icon class or extra <span>
|
|
tags showing the node status, etc. SilverStripe tree node will be typically rendered into html
|
|
code like this:
|
|
|
|
:::ss
|
|
...
|
|
<ul>
|
|
...
|
|
<li id="record-15" class="class-Page closed jstree-leaf jstree-unchecked" data-id="15">
|
|
<ins class="jstree-icon"> </ins>
|
|
<a class="" title="Page type: Page" href="admin/page/edit/show/15">
|
|
<ins class="jstree-checkbox"> </ins>
|
|
<ins class="jstree-icon"> </ins>
|
|
<span class="text">
|
|
<span class="jstree-pageicon"></span>
|
|
<span class="item" title="Deleted">New Page</span>
|
|
<span class="badge deletedonlive">Deleted</span>
|
|
</span>
|
|
</a>
|
|
</li>
|
|
...
|
|
</ul>
|
|
...
|
|
|
|
By applying the proper style sheet, the snippet html above could produce the look of:
|
|
![Page Node Screenshot](../../../_images/tree_node.png "Page Node")
|
|
|
|
SiteTree is a [api:DataObject] which is versioned by [api:Versioned] extension.
|
|
Each node can optionally have publication status flags, e.g. "Removed from draft".
|
|
Each flag has a unique identifier, which is also used as a CSS class for easier styling.
|
|
|
|
Developers can easily add a new flag, delete or alter an existing flag on how it is looked
|
|
or changing the flag label. The customization of these lozenges could be done either through
|
|
inherited subclass or [api:DataExtension]. It is just really about how we change the return
|
|
value of function `SiteTree->getTreeTitle()` by two easily extendable methods
|
|
`SiteTree->getStatusClass()` and `SiteTree->getStatusFlags()`.
|
|
|
|
Note: Though the flag is not necessarily tie to its status of __publication__ and it could
|
|
be used for flagging anything you like, we should keep this lozenge to show version-related
|
|
status, while let `SiteTree->CMSTreeClasses()` to deal with other customised classes, which
|
|
will be used for the class attribute of <li> tag of the tree node.
|
|
|
|
### Add new flag
|
|
__Example: using a subclass__
|
|
|
|
:::php
|
|
class Page extends SiteTree {
|
|
public function getScheduledToPublish(){
|
|
// return either true or false
|
|
}
|
|
|
|
public function getStatusFlags($cached = true) {
|
|
$flags = parent::getStatusFlags($cached);
|
|
$flags['scheduledtopublish'] = "Scheduled To Publish";
|
|
return $flags;
|
|
}
|
|
}
|
|
|
|
The above subclass of [api:SiteTree] will add a new flag for indicating its
|
|
__'Scheduled To Publish'__ status. The look of the page node will be changed
|
|
from ![Normal Page Node](../../../_images/page_node_normal.png) to ![Scheduled Page Node](../../../_images/page_node_scheduled.png). The getStatusFlags has an `updateStatusFlags()`
|
|
extension point, so the flags can be modified through `DataExtension` rather than
|
|
inheritance as well. Deleting existing flags works by simply unsetting the array key.
|