mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +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
|
* Return the entire site tree as a nested set of ULs
|
||||||
*/
|
*/
|
||||||
public function SiteTreeAsUL() {
|
public function SiteTreeAsUL() {
|
||||||
$this->generateDataTreeHints();
|
|
||||||
$this->generateTreeStylingJS();
|
$this->generateTreeStylingJS();
|
||||||
|
|
||||||
// Pre-cache sitetree version numbers for querying efficiency
|
// Pre-cache sitetree version numbers for querying efficiency
|
||||||
@ -213,27 +212,43 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
|
|||||||
return $this->getsubtree($this->request);
|
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'] = array();
|
||||||
|
$def['Root']['disallowedChildren'] = array();
|
||||||
|
$def['Root']['disallowedParents'] = array();
|
||||||
|
|
||||||
foreach($classes as $class) {
|
foreach($classes as $class) {
|
||||||
$obj = singleton($class);
|
$obj = singleton($class);
|
||||||
if($obj instanceof HiddenClass) continue;
|
if($obj instanceof HiddenClass) continue;
|
||||||
|
|
||||||
$allowedChildren = $obj->allowedChildren();
|
$allowedChildren = $obj->allowedChildren();
|
||||||
if($allowedChildren != "none") $def[$class]['allowedChildren'] = $allowedChildren;
|
//SiteTree::allowedChildren() returns null rather than an empty array if SiteTree::allowed_chldren == 'none'
|
||||||
$def[$class]['defaultChild'] = $obj->defaultChild();
|
if ($allowedChildren == null) $allowedChildren = array();
|
||||||
$def[$class]['defaultParent'] = isset(SiteTree::get_by_link($obj->defaultParent())->ID) ? SiteTree::get_by_link($obj->defaultParent())->ID : null;
|
$def[$class]['disallowedChildren'] = array_keys(array_diff($classes, $allowedChildren));
|
||||||
|
|
||||||
if($obj->stat('can_be_root')) {
|
$defaultChild = $obj->defaultChild();
|
||||||
$def['Root']['allowedChildren'][] = $class;
|
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
|
return Convert::raw2xml(Convert::raw2json($def));
|
||||||
Requirements::customScript("siteTreeHints = " . Convert::raw2json($def) . ";");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generateTreeStylingJS() {
|
public function generateTreeStylingJS() {
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
<% include CMSPagesController_ContentToolbar %>
|
<% include CMSPagesController_ContentToolbar %>
|
||||||
</div>
|
</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
|
$SiteTreeAsUL
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user