Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MINOR Moved tree filtering in LeftAndMain from SiteTreeAsUL() into ge…

…tSiteTreeFor() to allow filtering the initial tree (via GET parameters), rather than just through getsubtree()
  • Loading branch information...
commit 0ef5d0b84f1d0101d9c734c500613ee0e289e9a0 1 parent 9b2b39a
@chillu chillu authored
Showing with 18 additions and 16 deletions.
  1. +17 −15 admin/code/LeftAndMain.php
  2. +1 −1  admin/javascript/LeftAndMain.Tree.js
View
32 admin/code/LeftAndMain.php
@@ -590,10 +590,22 @@ public function SiteTreeAsUL() {
* @return String Nested unordered list with links to each page
*/
function getSiteTreeFor($className, $rootID = null, $childrenMethod = null, $numChildrenMethod = null, $filterFunction = null, $minNodeCount = 30) {
+ // Filter criteria
+ $params = $this->request->getVar('q');
+ if(isset($params['FilterClass']) && $filterClass = $params['FilterClass']){
+ if(!is_subclass_of($filterClass, 'CMSSiteTreeFilter')) {
+ throw new Exception(sprintf('Invalid filter class passed: %s', $filterClass));
+ }
+ $filter = new $filterClass($params);
+ } else {
+ $filter = null;
+ }
+
// Default childrenMethod and numChildrenMethod
- if (!$childrenMethod) $childrenMethod = 'AllChildrenIncludingDeleted';
- if (!$numChildrenMethod) $numChildrenMethod = 'numChildren';
-
+ if(!$childrenMethod) $childrenMethod = ($filter && $filter->getChildrenMethod()) ? $filter->getChildrenMethod() : 'AllChildrenIncludingDeleted';
+ if(!$numChildrenMethod) $numChildrenMethod = 'numChildren';
+ if(!$filterFunction) $filterFunction = ($filter) ? array($filter, 'isPageIncluded') : null;
+
// Get the tree root
$record = ($rootID) ? $this->getRecord($rootID) : null;
$obj = $record ? $record : singleton($className);
@@ -657,22 +669,12 @@ function getSiteTreeFor($className, $rootID = null, $childrenMethod = null, $num
* If ID = 0, then get the whole tree.
*/
public function getsubtree($request) {
- if($filterClass = $request->requestVar('FilterClass')) {
- if(!is_subclass_of($filterClass, 'CMSSiteTreeFilter')) {
- throw new Exception(sprintf('Invalid filter class passed: %s', $filterClass));
- }
-
- $filter = new $filterClass($request->requestVars());
- } else {
- $filter = null;
- }
-
$html = $this->getSiteTreeFor(
$this->stat('tree_class'),
$request->getVar('ID'),
- ($filter) ? $filter->getChildrenMethod() : null,
+ null,
null,
- ($filter) ? array($filter, 'isPageIncluded') : null,
+ null,
$request->getVar('minNodeCount')
);
View
2  admin/javascript/LeftAndMain.Tree.js
@@ -213,7 +213,7 @@
};
var handledform = $(e.target).is('.cms-edit-form') ? $(e.target)[0] : $(e.target).find('.cms-edit-form')[0];
- var id = $(handledform.ID).val();
+ var id = handledform ? $(handledform.ID).val() : null;
// check if a form with a valid ID exists
if(id) {
Please sign in to comment.
Something went wrong with that request. Please try again.