mirror of
https://github.com/silverstripe/silverstripe-docsviewer
synced 2024-10-22 11:05:56 +02:00
FEATURE: allow 3 levels of navigation for the module. _getModulePages() should in theory support any depth of pages
This commit is contained in:
parent
1a5c88b469
commit
ef7c095533
@ -382,24 +382,9 @@ class DocumentationViewer extends Controller {
|
||||
if($page->Title != "Index") $linkParts[] = $page->Filename;
|
||||
|
||||
$page->Link = $this->Link($linkParts);
|
||||
|
||||
$page->LinkingMode = 'link';
|
||||
$page->Children = false;
|
||||
|
||||
if(isset($this->Remaining[0])) {
|
||||
if(strtolower($this->Remaining[0]) == $page->Filename) {
|
||||
$page->LinkingMode = 'current';
|
||||
|
||||
if(is_dir($page->Path)) {
|
||||
$children = DocumentationParser::get_pages_from_folder($page->Path);
|
||||
foreach($children as $child) {
|
||||
$child->Link = $this->Link(array($this->Remaining[0], $child->Filename));
|
||||
}
|
||||
|
||||
$page->Children = $children;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$page->Children = $this->_getModulePagesNested($page);
|
||||
}
|
||||
}
|
||||
|
||||
@ -409,6 +394,45 @@ class DocumentationViewer extends Controller {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the module pages under a given page. Recursive call for {@link getModulePages()}
|
||||
*
|
||||
* @param ArrayData CurrentPage
|
||||
* @param int Depth of page in the tree
|
||||
*
|
||||
* @return DataObjectSet|false
|
||||
*/
|
||||
private function _getModulePagesNested(&$page, $level = 0) {
|
||||
// only support 2 more levels
|
||||
if(isset($this->Remaining[$level])) {
|
||||
|
||||
if(strtolower($this->Remaining[$level]) == $page->Filename) {
|
||||
|
||||
// its either in this section or is the actual link
|
||||
$page->LinkingMode = (isset($this->Remaining[$level + 1])) ? 'section' : 'current';
|
||||
|
||||
if(is_dir($page->Path)) {
|
||||
$children = DocumentationParser::get_pages_from_folder($page->Path);
|
||||
|
||||
$segments = array();
|
||||
for($x = 0; $x <= $level; $x++) {
|
||||
$segments[] = $this->Remaining[$x];
|
||||
}
|
||||
|
||||
foreach($children as $child) {
|
||||
$child->Link = $this->Link(array_merge($segments, array($child->Filename)));
|
||||
$child->LinkingMode = 'link';
|
||||
$child->Children = $this->_getModulePagesNested($child, $level + 1);
|
||||
}
|
||||
|
||||
return $children;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the content for the page. If its an actual documentation page then
|
||||
* display the content from the page, otherwise display the contents from
|
||||
|
@ -8,7 +8,15 @@
|
||||
<% if Children %>
|
||||
<ul>
|
||||
<% control Children %>
|
||||
<li><a href="$Link" class="$LinkingMode">$Title</a></li>
|
||||
<li><a href="$Link" class="$LinkingMode">$Title</a>
|
||||
<% if Children %>
|
||||
<ul>
|
||||
<% control Children %>
|
||||
<li><a href="$Link" class="$LinkingMode">$Title</a></li>
|
||||
<% end_control %>
|
||||
</ul>
|
||||
<% end_if %>
|
||||
</li>
|
||||
<% end_control %>
|
||||
</ul>
|
||||
<% end_if %>
|
||||
|
Loading…
Reference in New Issue
Block a user