mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 11:05:53 +02:00
ENHANCEMENT 'data-hints' attribute into root of CMSMain site tree, changed from 'allowedParents' to 'disallowedParents', 'allowedChildren' to 'disallowedChildren' for brevity (fixes #6577)
This commit is contained in:
parent
42b31d4410
commit
b4366c9ca9
@ -139,7 +139,6 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
|
||||
* Return the entire site tree as a nested set of ULs
|
||||
*/
|
||||
public function SiteTreeAsUL() {
|
||||
$this->generateDataTreeHints();
|
||||
$this->generateTreeStylingJS();
|
||||
|
||||
// Pre-cache sitetree version numbers for querying efficiency
|
||||
@ -213,27 +212,43 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
|
||||
return $this->getsubtree($this->request);
|
||||
}
|
||||
|
||||
public function generateDataTreeHints() {
|
||||
$classes = ClassInfo::subclassesFor( $this->stat('tree_class') );
|
||||
/**
|
||||
* Create serialized JSON string with site tree hints data to be injected into
|
||||
* 'data-hints' attribute of root node of jsTree.
|
||||
*
|
||||
* @return String Serialized JSON
|
||||
*/
|
||||
public function SiteTreeHints() {
|
||||
$classes = ClassInfo::subclassesFor( $this->stat('tree_class') );
|
||||
|
||||
$def['Root'] = array();
|
||||
$def['Root']['disallowedChildren'] = array();
|
||||
$def['Root']['disallowedParents'] = array();
|
||||
|
||||
foreach($classes as $class) {
|
||||
$obj = singleton($class);
|
||||
if($obj instanceof HiddenClass) continue;
|
||||
|
||||
|
||||
$allowedChildren = $obj->allowedChildren();
|
||||
if($allowedChildren != "none") $def[$class]['allowedChildren'] = $allowedChildren;
|
||||
$def[$class]['defaultChild'] = $obj->defaultChild();
|
||||
$def[$class]['defaultParent'] = isset(SiteTree::get_by_link($obj->defaultParent())->ID) ? SiteTree::get_by_link($obj->defaultParent())->ID : null;
|
||||
|
||||
if($obj->stat('can_be_root')) {
|
||||
$def['Root']['allowedChildren'][] = $class;
|
||||
//SiteTree::allowedChildren() returns null rather than an empty array if SiteTree::allowed_chldren == 'none'
|
||||
if ($allowedChildren == null) $allowedChildren = array();
|
||||
$def[$class]['disallowedChildren'] = array_keys(array_diff($classes, $allowedChildren));
|
||||
|
||||
$defaultChild = $obj->defaultChild();
|
||||
if ($defaultChild != 'Page' && $defaultChild != null) $def[$class]['defaultChild'] = $defaultChild;
|
||||
|
||||
$defaultParent = isset(SiteTree::get_by_link($obj->defaultParent())->ID) ? SiteTree::get_by_link($obj->defaultParent())->ID : null;
|
||||
if ($defaultParent != 1 && $defaultParent != null) $def[$class]['defaultParent'] = $defaultParent;
|
||||
|
||||
if(is_array($def[$class]['disallowedChildren'])) foreach($def[$class]['disallowedChildren'] as $disallowedChild) {
|
||||
$def[$disallowedChild]['disallowedParents'][] = $class;
|
||||
}
|
||||
|
||||
//Are any classes allowed to be parents of root?
|
||||
$def['Root']['disallowedParents'][] = $class;
|
||||
}
|
||||
|
||||
// Put data hints into a script tag at the top
|
||||
Requirements::customScript("siteTreeHints = " . Convert::raw2json($def) . ";");
|
||||
return Convert::raw2xml(Convert::raw2json($def));
|
||||
}
|
||||
|
||||
public function generateTreeStylingJS() {
|
||||
|
@ -34,7 +34,7 @@
|
||||
<% include CMSPagesController_ContentToolbar %>
|
||||
</div>
|
||||
|
||||
<div class="cms-tree" data-url-tree="$Link(getsubtree)" data-url-savetreenode="$Link(savetreenode)">
|
||||
<div class="cms-tree" data-url-tree="$Link(getsubtree)" data-url-savetreenode="$Link(savetreenode)" data-hints="$SiteTreeHints">
|
||||
$SiteTreeAsUL
|
||||
</div>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user